0

enter image description here

My code is:

var client = new HttpClient { BaseAddress = new Uri("http://bf4stats.com") };
        client.DefaultRequestHeaders.Add("Referer", ":http://bf4stats.com/pc/Azezeil");
        client.DefaultRequestHeaders.Add("X-Requested-With", ": XMLHttpRequest");
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        HttpResponseMessage response = client.PostAsync("/pc/Azezeil", new StringContent("{" + "\"" + "request" + "\"" + ":" + "\"" + "updatePlayer" + "\"" + "}", Encoding.UTF8, "application/json")).Result;
        string res = await response.Content.ReadAsStringAsync();

The response come failed 417. How to make a POST request with HttpClient or any thing works on Windows Store apps C#?

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
Medo Omar
  • 81
  • 8

1 Answers1

1

Error 417 is "Expectation Failed". This is because, when you do a POST, by default HttpClient will send a Expect Continue header and wait for a 100 response before continuing with the POST. To disable this behavior, you can do,

httpClient.DefaultRequestHeaders.ExpectContinue = false;
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243