当前位置: 首页>>代码示例>>C#>>正文


C# HttpWebRequest.ResetRequest方法代码示例

本文整理汇总了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;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:93,代码来源:HttpWebRequest.cs


注:本文中的System.Net.HttpWebRequest.ResetRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。