如何将VB应用程序代理设置设置为默认系统代理设置

时间:2013-06-03 13:09:09

标签: vb.net proxy ip

我的应用程序应该在启用了代理的公司网络上运行, 默认情况下,登录浏览器等所有应用程序时都可以正常访问互联网

但当我打开我的应用程序时“远程服务器返回错误[407]需要代理身份验证”错误即将到来

在普通互联网连接的PC上运行良好

是否有任何方法可以设置手动代理,或者更优选地将系统代理设置为应用程序的默认代理 我在编程领域太新手了

我的代码是

Dim PartURL As String = "http://www.google.com"
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(PartURL)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim sourcecode As String = sr.ReadToEnd()
SearchPageSource = sourcecode

我的代理设置也是

Address: abcserver04
Port:    8080

cmd提示符下的Ipconfig输出是

Ethernet adapter local area connection
Connection Specific DNS Suffix : abc.defgroup.net
IP Address : 10.4.8.xx
Subnet Mask : 255.255.255.0
Default Gateway : 10.4.8.254

2 个答案:

答案 0 :(得分:2)

试试这个......

request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials

答案 1 :(得分:0)

您也可以使用app.config

来自https://stackoverflow.com/a/8180854/239408

<system.net>
  <defaultProxy useDefaultCredentials="true" />
</system.net>