1

Does the .NET WebClient follow the Location header which should be sent together with a 201 Created response? If yes, is there a way to disable it?

Additionally I'm looking for a way to retrieve the value of the Location header as I'd like to display the link of the created resource to the user.

1 Answer 1

3

Checked the .NET framework sourcecode and here's the answer: WebClient uses HttpWebRequest which uses the following logic for following redirects:

else if (AllowAutoRedirect && (
    ResponseStatusCode==HttpStatusCode.Ambiguous          || // 300
    ResponseStatusCode==HttpStatusCode.Moved              || // 301
    ResponseStatusCode==HttpStatusCode.Redirect           || // 302
    ResponseStatusCode==HttpStatusCode.RedirectMethod     || // 303
    ResponseStatusCode==HttpStatusCode.RedirectKeepVerb ))   // 307
{

The value of the Location header is in the ResponseHeaders collection of the WebClient (or the event args when using async).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.