我想知道爲什麼我的HTTP請求返回響應500服務器內部錯誤。C#HttpWebRequest返回500內部錯誤
我用這個C#代碼
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://svabyss.66ghz.com/getmsg.php");
req.ContentLength = ("receiver=" + b.ToString() + "&PHPSESSID=" + _SESSIONID).Length;
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
req.KeepAlive = true;
req.CookieContainer = new CookieContainer();
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
req.Headers[HttpRequestHeader.Pragma] = "cache";
req.UseDefaultCredentials = true;
req.Credentials = CredentialCache.DefaultNetworkCredentials;
req.PreAuthenticate = true;
req.Proxy = new WebProxy("http://svabyss.66ghz.com:80", true);
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.Write("receiver=" + b.ToString() + "&PHPSESSID=" + _SESSIONID);
writer.Flush();
writer.Dispose();
try
{
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
OperationCompleted(new SVWorkerEventArgs("GET|" + b.ToString(), reader.ReadToEnd()));
response.Close();
reader.Dispose();
}
catch (WebException ex)
{
StreamReader str = new StreamReader(ex.Response.GetResponseStream());
string err = str.ReadToEnd();
}
我不知道至極頭,我錯過。任何幫助將是偉大的!
感謝..
問題修正
我收到通過由服務器返回的錯誤消息的回覆。錯誤信息實際上是我想要的結果。
現在,我不在乎什麼服務器回覆我。閹了404或505,返回的錯誤信息是我想要的..
謝謝你們:)
您是否嘗試過沒有'Proxy'? – dtb
你爲什麼要指定所有這些設置? –
我的第一個代碼只是 'req.ContentType =「應用/的X WWW的形式進行了urlencoded」;' 只有這頭值我設置,它的返回相同的錯誤 –