技术开发 频道

Http访问代理使用


【IT168技术文档】

  1、GlobalProxySelection 类

  包含所有 HTTP 请求的全局默认代理实例。
  2、代码示例
if(Setting.NeedProxy) { GlobalProxySelection.Select = SetupProxy(); } //Create a new request HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(requestURL); if(null==HttpWRequest) { Logger.Write("web request failed"); return false; } private WebProxy SetupProxy() { // if a proxyURL is specified in the configuration file, // create a WebProxy object for later use. WebProxy mProxy = null; string proxyURL = Setting.ProxyURL; if (proxyURL != null) { int proxyPort = GetProxyPort(); if (proxyPort > 0) { mProxy = new WebProxy(proxyURL, proxyPort); } else { mProxy = new WebProxy( proxyURL ); } // if a proxyUser is specified in the configuration file, // set up the proxy object's Credentials. string proxyUser = Setting.ProxyUser; if (proxyUser != null) { string proxyPassword = Setting.ProxyPassword; string proxyDomain = Setting.ProxyDomain; if (proxyDomain != null) { mProxy.Credentials = new NetworkCredential(proxyUser, proxyPassword, proxyDomain); } else { mProxy.Credentials = new NetworkCredential(proxyUser, proxyPassword); } } } return mProxy; }
0
相关文章