我正在尝试使用以下代码以编程方式登录,直到两天前它工作正常,但现在突然我收到一个 WebException “远程服务器返回错误:(417)预期失败 -”如何解决这个问题。
我还尝试了为什么我收到此错误中发布的解决方案:远程服务器返回错误:(417)预期失败
谁能告诉我如何解决这个问题。
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://sms.ultoo.com/login.php");
String Postdata = "LoginMobile=9999999999&LoginPassword=aaa";
webRequest.Timeout = 10 * 60 * 1000;
webRequest.Method = "POST";
webRequest.ContentType = ContentType;
webRequest.ContentLength = Postdata.Length;
// POST the data
using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter2.Write(Postdata);
}
// This actually does the request and gets the response back
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
string ResponseData = string.Empty;
using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
{
// dumps the HTML from the response into a string variable
ResponseData = responseReader.ReadToEnd();
}
导致异常的语句
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();