本文整理汇总了C#中System.Net.Http.HttpResponseMessage.IsRedirectStatusCode方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.IsRedirectStatusCode方法的具体用法?C# HttpResponseMessage.IsRedirectStatusCode怎么用?C# HttpResponseMessage.IsRedirectStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpResponseMessage
的用法示例。
在下文中一共展示了HttpResponseMessage.IsRedirectStatusCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRedirect
/// <summary>
/// Handles redirect if the response's status code is redirect, redirects are turned on, and the header has
/// a location.
/// When the status code is <c>303</c> the method on the request is changed to a GET as per the RFC2616
/// specification. On a redirect, it also removes the <c>Authorization</c> and all <c>If-*</c> request headers.
/// </summary>
/// <returns> Whether this method changed the request and handled redirect successfully. </returns>
private bool HandleRedirect(HttpResponseMessage message)
{
// TODO(peleyal): think if it's better to move that code to RedirectUnsucessfulResponseHandler
var uri = message.Headers.Location;
if (!message.IsRedirectStatusCode() || uri == null)
{
return false;
}
var request = message.RequestMessage;
request.RequestUri = new Uri(request.RequestUri, uri);
// Status code for a resource that has moved to a new URI and should be retrieved using GET.
if (message.StatusCode == HttpStatusCode.SeeOther)
{
request.Method = HttpMethod.Get;
}
// Clear Authorization and If-* headers.
request.Headers.Remove("Authorization");
request.Headers.IfMatch.Clear();
request.Headers.IfNoneMatch.Clear();
request.Headers.IfModifiedSince = null;
request.Headers.IfUnmodifiedSince = null;
request.Headers.Remove("If-Range");
return true;
}