程序中如何通过代理服务器访问
程序中通过webclient来获取web页面内容:
Dim MyClient As New System.Net.WebClient
Dim Urlstr As String="http://www.sina.com.cn" '页面地址
Dim response As System.IO.Stream
Dim SrReadToEnd As System.IO.StreamReader
response = MyClient.OpenRead(Urlstr)
SrReadToEnd = New System.IO.StreamReader(response, System.Text.Encoding.Default)
While SrReadToEnd.Peek <> -1
'遍历网页内容
End While
现在如果要通过代理服务器访问的话,该怎么搞?感谢各位大侠指教!
[解决办法]
//创建 代理服务器设置对象 的实例
Dim MyClient as System.Net.WebProxy = new System.Net.WebProxy("172.24.2.98:8080");
//代理服务器需要验证
MyClient.BypassProxyOnLocal=false;
//用户名密码
MyClient.Credentials = new NetworkCredential("xxx", "xxx");
[解决办法]
用WebResponse可以支持代理。WebClient是缩水的不支持代理
[解决办法]
呵呵,说的太形象了,,,缩水啊。。。。我倒是知道怎么弄的整个上网都使用代理。。。。