我正在开发一个登录网页并获取一些数据的WinRT应用程序。问题是我收到“HttpRequestException:发送请求时发生错误”消息。这是代码:
Uri url = new Uri("https://miyoigo-b.yoigo.com/selfcare/login");
HttpContent msg = new StringContent("account[cli]=" + number + "&password=" + pass);
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
handler.UseCookies = true;
handler.CookieContainer = new CookieContainer();
HttpClient req = new HttpClient(handler);
req.DefaultRequestHeaders.Add("Host", "miyoigo-b.yoigo.com");
req.DefaultRequestHeaders.ExpectContinue = false;
HttpResponseMessage response = await req.PostAsync(url, msg);
string responseBody = await response.Content.ReadAsStringAsync();
我一直在尝试通过互联网找到的很多东西,甚至禁用我的防火墙,但没有任何效果。我正在从Windows Phone应用程序移植它,它确实可以使用它:
Uri url = new Uri("https://miyoigo-b.yoigo.com/selfcare/login");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "POST";
req.Headers["Host"] = "miyoigo-b.yoigo.com";
req.CookieContainer = new CookieContainer();
req.BeginGetRequestStream(new AsyncCallback(WriteCallback), req);
之后,在Callback中我创建了一个Stream并编写了凭据。
任何想法?我知道问题只出现在这个网页上,也许我忘记发送一些内容或者POST内容的格式不正确......
由于
答案 0 :(得分:0)
最后问题是Win8 Metro Apps只接受SSL3.1,而且这个网页使用的是SSL3.0。解决方案是使用新版本的网页。
谢谢大家