开发者

Does WebClient follow Location headers when getting a 201 response?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜