日期:2014-05-17  浏览次数:22027 次

WebRequest如何设置socks5代理?
翻遍百度和谷歌就是找不到,只好来请教各位大虾了。
C# code
            WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
            request.Credentials = CredentialCache.DefaultCredentials;

            request.Proxy = xxx?

            HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
            Console.WriteLine (response.StatusDescription);
            Stream dataStream = response.GetResponseStream ();
            StreamReader reader = new StreamReader (dataStream);
            string responseFromServer = reader.ReadToEnd ();
            Console.WriteLine (responseFromServer);
            reader.Close ();
            dataStream.Close ();
            response.Close ();


------解决方案--------------------
可以在 <system.net> 配置节中配置 HttpWebRequest 的属性,包括 WebProxy
XML code
<system.net>    
  <connectionManagement>    
  </connectionManagement>   
  <defaultProxy>    
    <proxy proxyaddress="http://xxx.xxx.xxx.xxx:xxx" bypassonlocal="False"/>    
  </defaultProxy>   
  <settings>    
      <httpWebRequest useUnsafeHeaderParsing="true"/>   
      <servicePointManager checkCertificateName="true"     
                           checkCertificateRevocationList="true"      
                           enableDnsRoundRobin="true"     
                           expect100Continue="true"       
                           useNagleAlgorithm="true"/>      
  </settings>   
</system.net>

------解决方案--------------------
socket 5? 没注意看。。。我记得 WebProxy 是不支持编程方式设置socket代理的。

参考:http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/982bef6c-b9a4-4c0d-b7d5-0c64df9f610a