本文整理汇总了C#中System.Net.HttpWebRequest.ResetRequest方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest.ResetRequest方法的具体用法?C# HttpWebRequest.ResetRequest怎么用?C# HttpWebRequest.ResetRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpWebRequest
的用法示例。
在下文中一共展示了HttpWebRequest.ResetRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Recurse
/* returns this WebRequest or a new one.
* If nothing can be done, it will return the same 'ol
* request.
* Note: will change substantially soon*/
public WebRequest Recurse(HttpWebRequest request,HttpWebResponse response)
{
HttpStatusCode code=response.StatusCode;
switch(code)
{
case HttpStatusCode.OK:
{
if(http==HttpAuthState.Trying) http=HttpAuthState.OK;
if(proxy==HttpAuthState.Trying) proxy=HttpAuthState.OK;
return request;
}
break; /* never reached */
case HttpStatusCode.ProxyAuthenticationRequired:
{
String challenge=null;
if(proxy==HttpAuthState.Trying || proxy==HttpAuthState.Failed)
{
proxy=HttpAuthState.Failed;
return request;
}
challenge=response.Headers["Proxy-Authenticate"];
request.ResetRequest(false);
if(request.AddProxyAuthHeaders(challenge))
{
request.ResetRequest(true);
proxy=HttpAuthState.Trying;
return request;
}
else
{
proxy=HttpAuthState.Failed;
return request;
}
}
break;
case HttpStatusCode.Forbidden:
{
String challenge=null;
if(http==HttpAuthState.Trying || http==HttpAuthState.Failed)
{
http=HttpAuthState.Failed;
return request;
}
challenge=response.Headers["WWW-Authenticate"];
request.ResetRequest(false);
if(request.AddHttpAuthHeaders(challenge))
{
request.ResetRequest(true);
http=HttpAuthState.Trying;
return request;
}
else
{
http=HttpAuthState.Failed;
return request;
}
}
break;
case HttpStatusCode.Redirect:
case HttpStatusCode.Moved :
case HttpStatusCode.MultipleChoices :
case HttpStatusCode.SeeOther :
case HttpStatusCode.TemporaryRedirect:
/* case HttpStatusCode.Found : // Duplicate */
/* case HttpStatusCode.MovedPermanently : // Duplicate */
{
Uri newUri=response.ResponseUri;
if(request.allowAutoRedirect && newUri!=null &&
redirections<request.MaximumAutomaticRedirections &&
(request.Method=="GET" || request.Method=="HEAD"))
{
/* ok redirect it */
request.ResetRequest(true);
request.SetAddress(newUri);
redirections++;
return request;
}
}
break;
}
return request;
}