我試圖以編程方式搜索上述網站上的項目。httpwebresponse does not work
以下不適合我。響應實際上是一個錯誤頁面,而不是搜索結果頁面。
請幫忙。
string sUrl = "http://www.arrownac.com/";
string sUrl1 = "http://app.arrownac.com/aws/pg_webc?s=P";
HttpWebRequest owebreq = (HttpWebRequest)WebRequest.Create(sUrl1);
owebreq.Referer = sUrl;
ASCIIEncoding encoding = new ASCIIEncoding();
string postdata = "search_token=" + "743C083102JPTR";
byte[] data = encoding.GetBytes(postdata);
owebreq.ContentType = "text/html";
//"application/x-www-form-urlencoded";
owebreq.Method = "POST";
owebreq.ContentLength = data.Length;
Stream newStream = owebreq.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse owebresp = (HttpWebResponse)owebreq.GetResponse();
string sResult = string.Empty;
using (StreamReader sr = new StreamReader(owebresp.GetResponseStream()))
{
sResult = sr.ReadToEnd();
sr.Close();
}
嗯,什麼不起作用?你有調試過嗎?你會得到錯誤,如果是的話,是什麼錯誤(如果頁面是什麼代碼)?告訴更多關於你的問題的事情,否則你不會得到很好的答案! – Younes 2010-10-13 11:49:55
沒有代碼錯誤,它執行得很好。但我得到的響應輸出爲<! - Vignette V6 Wed Oct 13 08:58:23 2010 - >