日期:2014-05-17 浏览次数:22027 次
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> <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