作者senjor (哞哞)
看板C_Sharp
标题[问题] HttpWebRequest 收回网页的问题
时间Tue Jul 10 14:19:12 2007
小弟要写一个将一个输入序列传至指定网页之程式
也利用了fiddler把那个网页的变数找出来了
可是为什麽送出去资料之後
收回的传回网页
还是等於没有送过post的网页?
我也试过用cookie保持session之类的方法
不知道有没有大大比较了解httpwebrequest post的用法
看看我是不是哪里观念错误了
能够帮忙小弟一下
因为问过很多人也翻过很多书
可是好像都没有提到类似的东西跟问题
才不得已把程式码PO在这里求教
希望大大们能告知一下错误
或者指点一下哪里有参考资料..
感激不尽 Orz
以下是程式码:
private void button1_Click(object sender, EventArgs e)
{
CookieContainer cookie = new CookieContainer();
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create("
http://www.cbs.dtu.dk/services/NetPhos/");
myHttpWebRequest.Method = "POST";
myHttpWebRequest.CookieContainer = cookie;
string postData =
HttpUtility.HtmlEncode("configfile=/usr/opt/www/pub/CBS/services/NetPhos-2.0/NetPhos.cf&"
+
"SEQPASTE=<KLVDTANFDDYMKALGVGFATRQMAGLTKEISFKLDEEFDETTADDRHVKKLILTLTMGNVVSTRTYPTTI&"
+
"SEQSUB=");
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);
myHttpWebRequest.ContentType = " application/octet-stream";
myHttpWebRequest.ContentLength = byte1.Length;
Stream newStream = myHttpWebRequest.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
MessageBox.Show("The value of 'ContentLength' property after
sending the data is "+ myHttpWebRequest.ContentLength);
newStream.Close();
HttpWebResponse myResp =
(HttpWebResponse)myHttpWebRequest.GetResponse();
StreamReader myReader = new
StreamReader(myResp.GetResponseStream());
webBrowser1.DocumentText = myReader.ReadToEnd();
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.70.85.138
1F:→ senjor:已解决 07/11 10:28