1

我正在尝试使用以下代码以编程方式登录,直到两天前它工作正常,但现在突然我收到一个 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();
4

1 回答 1

1

感谢所有花时间回答我的问题的人。

我尝试了http-post-returns-the-error-417-expectation-failed-c中发布的解决方案, 它对我有用。

我只需要添加以下代码

System.Net.ServicePointManager.Expect100Continue = false;
于 2012-12-03T11:23:55.157 回答