0

I have a problem with HttpClient (System.Net.Http.HttpClient).

I send a POST to a website to connect to my personnal space:

  • On Windows 8.1 : it works great, I am conencted (Response : HTTP OK)

  • On Windows Phone 8.1 : the connection does'nt work (Response : HTTP FOUND and not HTTP OK)

What is the diffrence between the two platforms ?

I use the following code :

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);

Edit : I don't use Windows.Web.Http.HttpClient because when I use it I have an Hresult on a specific website (it works on other websites) I found the problem, HttpClient doesn't support automatic redirection whereas it is supported on Windows 8.1

Geotinc
  • 289
  • 1
  • 4
  • 21
  • Any specific reason why you're not using the `Windows.Web.Http.HttpClient`? – Fred Nov 15 '14 at 16:28
  • I have the following error with Windows.Web.Http.HttpClient : A redirect request will change a secure to a non-secure connection How to handle it ? – Geotinc Nov 17 '14 at 19:30

0 Answers0