小弟最近在測試透過 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