我的问题是关于 pac 文件和 .net 应用程序来使用它进行连接。
基本上我有一个 HttpWebRequest 和 HttpWebResponse,当我创建一个 HttpWebRequest 时,因为我在代理后面,所以我必须使用代理连接到外部世界。所以在我的代理设置中,我必须使用 PAC 文件来获取正确的地址,但是当我使用 pac 文件时,我收到以下错误:
{"The underlying connection was closed: An unexpected error occurred on a receive."}
内部异常:
{"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
我确定这与错误使用 PAC 文件有关,因为例如,如果我从 pac 文件中获取代理 IP 地址,我可以连接,但我当然想使用 pac 文件作为连接规则互联网。
这是我的代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileUrl); request.Method = "GET";
request.AllowAutoRedirect=true;
request.CookieContainer = new CookieContainer();
request.KeepAlive = true;
WebProxy proxy = new WebProxy("http://.../proxy.pac");
NetworkCredential networkCredential = new NetworkCredential(UsrData.username, UsrData.password);
proxy.Credentials = networkCredential;
request.Proxy = proxy;
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
{
....
}
}
对于请求,这里是 pac 的简短版本:
function FindProxyForURL(url, host)
{
if ( shExpMatch(host,"bbcs.companyname.com"))
return "PROXY 158.169.10.11:8010; "+
"PROXY 158.169.132.11:8010";
if ( !shExpMatch(host,"*.*") ||
shExpMatch(host,"intragate*.compname.com") ||
shExpMatch(host,"127.0.0.*") ||
shExpMatch(host,"10.*.*.*") ||
shExpMatch(host,"192.168.*") ||
shExpMatch(host,"139.191.*") ||
)
return "DIRECT";
if (isInNet(myIpAddress(), "158.166.0.0","255.255.128.0") ||
isInNet(myIpAddress(), "158.168.0.0", "255.255.0.0"))
return "PROXY 158.165.132.13:8010; " +
"PROXY 158.165.5.11:8010";
else
return "PROXY 158.169.10.11:8010; " +
"PROXY 158.169.132.11:8010";
}
知道我想念什么吗?
使用 PacTester 并浏览某个 url 我得到了 PROXY + ip 的返回,这可能是返回词 PROXY 的原因吗?itp 也不是完全正确的路径,不像“http://ip...”