作者huge (huge)
看板C_Sharp
标题[问题] 请问使用POST的问题
时间Thu Apr 10 22:56:40 2008
小弟最近在测试透过 POST 方式取得网页的资讯
然而在连结
http://www.ticket.com.tw/search 也就是年代售票网的活动消息
发现我撰写以下的程式
到了 HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); 这一行
都会出现 HTTP 500 内部伺服器错误
所以想请教各位,小弟这模拟POST的程式是否有什麽错误呢?
string SearchPage = @"
http://www.ticket.com.tw/search.asp";
String strPost = "KeyWord=&TypeRead=0&SelArea=0&SelYear=0&SelMonth=0&SelDate=0";
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(SearchPage);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.Referer = @"
http://www.ticket.com.tw/";
try {
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception ex) {
}
finally {
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) {
string result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 124.10.5.203