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


C# HttpWebRequest.AddProxyAuthHeaders方法代码示例

本文整理汇总了C#中System.Net.HttpWebRequest.AddProxyAuthHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest.AddProxyAuthHeaders方法的具体用法?C# HttpWebRequest.AddProxyAuthHeaders怎么用?C# HttpWebRequest.AddProxyAuthHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.HttpWebRequest的用法示例。


在下文中一共展示了HttpWebRequest.AddProxyAuthHeaders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendConnect

		private static void SendConnect(Socket sock, HttpWebRequest req)
		{
			// This stream does not own the socket
			Stream stream = new NetworkStream(sock, false);
			StreamWriter writer = new StreamWriter(stream);
			String connectString = null;
			String authHeader = null;
			
			if(req.Proxy.Credentials != null)
			{
				// TODO : remove this from the SSL req
				req.AddProxyAuthHeaders("Basic");
			}		
						
			connectString= 	"CONNECT "+	req.Address.Host + 
							":" + req.Address.Port +
							" HTTP/"+req.protocolVersion.Major+
							"."+req.protocolVersion.Minor+"\r\n";

			authHeader = 	"Proxy-Authorization: " + 
							req.Headers["Proxy-Authorization"] + "\r\n"; 

			writer.Write(connectString);
			writer.Write(authHeader);
			writer.Write("\r\n");// terminating CRLF
			writer.Flush();
			writer.Close();
			// stream is automatically closed , but the socket is
			// still alive
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:30,代码来源:HttpWebRequest.cs

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