我对 HttpClient (System.Net.Http.HttpClient) 有疑问。
我向网站发送 POST 以连接到我的个人空间:
在 Windows 8.1 上:效果很好,我已经连接(响应:HTTP OK)
在 Windows Phone 8.1 上:连接不起作用(响应:HTTP FOUND 而不是 HTTP OK)
两个平台有什么区别?
我使用以下代码:
System.Net.Http.HttpResponseMessage msg1 = await this._client.GetAsync(new Uri(UrlLogin));
HtmlDocument document1 = new HtmlDocument();
document1.LoadHtml(await msg1.Content.ReadAsStringAsync());
List<KeyValuePair<String, String>> hiddenInputNodes1 = document1.DocumentNode.Descendants().Where(x => x.GetAttributeValue("type") == "hidden" && x.Name == "input").Select(x => new KeyValuePair<String, String>(x.GetAttributeValue("name"), x.GetAttributeValue("value"))).ToList();
List<KeyValuePair<String, String>> list1 = new List<KeyValuePair<string, string>>();
list1.Add(new KeyValuePair<String, String>("username", username));
list1.Add(new KeyValuePair<String, String>("password", password));
list1.AddRange(hiddenInputNodes1);
System.Net.Http.HttpResponseMessage msg2 = await this._client.PostAsync(new Uri(UrlConnection), new FormUrlEncodedContent(list1));
return (msg2.RequestMessage.RequestUri.ToString() == UrlAccount);
编辑:我不使用 Windows.Web.Http.HttpClient,因为当我使用它时,我在特定网站上有一个 Hresult(它适用于其他网站)我发现了问题,HttpClient 不支持自动重定向,但它受支持在 Windows 8.1 上