Using HttpClient from NuGet.
The app sends a post with client.PostAsync(). I’d like it to NOT follow 302 redirects.
how?
I figure I can just set AllowAutoRedirect as described in this answer.
But how do I get the HttpWebRequest used within a PostAsync() call?
One of the overloads of the
HttpClientconstructor takes aWebRequestHandlerargument. TheHttpClientclass uses thisWebRequestHandlerfor sending requests.The
WebRequestHandlerclass provides a property calledAllowAutoRedirectto configure the redirect behaviour. Setting this property to false
instructs the
HttpClientto not follow redirect responses.Here is a small code sample: