尝试 PutAsync 时出现 HttpRequestException
HttpRequestException when trying PutAsync
我正在开发 Windows 10 通用应用程序,当我尝试执行以下操作时,我不断收到 "The HTTP redirect request must be confirmed by the user" 错误:
HttpClient http = new HttpClient();
HttpResponseMessage response = new HttpResponseMessage();
response = await http.PutAsync(url, new StringContent(temp));
有什么处理方法吗?
我通过将 AllowAutoRedirect 设置为 false 然后手动调用重定向找到了解决该问题的方法。
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));
我正在开发 Windows 10 通用应用程序,当我尝试执行以下操作时,我不断收到 "The HTTP redirect request must be confirmed by the user" 错误:
HttpClient http = new HttpClient();
HttpResponseMessage response = new HttpResponseMessage();
response = await http.PutAsync(url, new StringContent(temp));
有什么处理方法吗?
我通过将 AllowAutoRedirect 设置为 false 然后手动调用重定向找到了解决该问题的方法。
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));