2012-11-28 115 views
1

我有一个连接到一个Web服务,并有一个选项来添加代理服务器的详细信息。这工作正常。然而,当代理不仅仅是一个地址,而是一个文件名的地址时,它似乎就会失败。WebProxy的Web服务连接

myproxy.com/proxypac.asp 

这是这个文件名在最后似乎给我的问题。我正在初始化我的WebProxy,

System.Net.WebProxy wp = new System.Net.WebProxy(location.ProxyAddress, location.ProxyPort); 

任何人都可以提供任何指针吗?

+0

“看来要失败” ......与异常?你怎么知道一定的? –

+0

看看这篇文章:http://msdn.microsoft.com/en-us/magazine/cc300743.aspx –

+0

错误很简单; '远程服务器返回错误:(400)错误的请求。' – creatiive

回答

1

你试过:

WebProxy proxy = new WebProxy(@"http://myproxy.com/proxypac.asp"); 

或者

WebProxy proxy = WebRequest.GetSystemWebProxy(); 

一种解决方法是打开你的文件,并检查其内容看代理ADRESS和端口你。

如果您下载myproxy.com/proxypac.asp文件时,它应该是这样的:

function FindProxyForURL(url, host) { 
     // our local URLs from the domains below example.com don't need a proxy: 
     if (shExpMatch(url,"*.example.com/*")) {return "DIRECT";} 
     if (shExpMatch(url, "*.example.com:*/*")) {return "DIRECT";} 

     // URLs within this network are accessed through 
     // port 8080 on fastproxy.example.com: 
     if (isInNet(host, "10.0.0.0", "255.255.248.0")) { 
     return "PROXY fastproxy.example.com:8080"; 
     } 

     // All other requests go through port 8080 of proxy.example.com. 
     // should that fail to respond, go directly to the WWW: 
     return "PROXY proxy.example.com:8080; DIRECT"; 
    }