Search code examples
c#windows-runtimewin-universal-appwindows-10windows-10-mobile

HttpRequestException when trying PutAsync


I'm working on a Windows 10 Universal app and I keep getting a "The HTTP redirect request must be confirmed by the user" error when I try to do the following:

HttpClient http = new HttpClient();
HttpResponseMessage response = new HttpResponseMessage();
response = await http.PutAsync(url, new StringContent(temp));

Any ideas on how to handle that?


Solution

  • I managed to find a workaround to the problem by setting AllowAutoRedirect to false and then making a call to the redirect manually.

            HttpClientHandler clientHandler = new HttpClientHandler();
            clientHandler.AllowAutoRedirect = false;
    
            HttpClient http = new HttpClient(clientHandler);
            HttpResponseMessage response = new HttpResponseMessage();
            response = await http.PutAsync(url, new StringContent(temp));
    
            url = response.Headers.Location;
            response = await http.PutAsync(url, new StringContent(temp));