开发者

Does WebClient follow Location headers when getting a 201 response?

开发者 https://www.devze.com 2023-01-26 08:50 出处:网络
Does the .NET WebClient follow the Location header which should be sent together with a 201 Created response? If yes, is there a way 开发者_C百科to disable it?

Does the .NET WebClient follow the Location header which should be sent together with a 201 Created response? If yes, is there a way 开发者_C百科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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消