C# pac文件中的Web代理和错误
我的问题是关于使用pac文件和.net应用程序进行连接的问题 基本上我有一个HttpWebRequest和HttpWebResponse,当我创建一个HttpWebRequest时,因为我在一个代理后面,所以我必须使用代理连接到外部世界。因此,在我的代理设置中,我必须使用PAC文件来获得正确的地址,但当我使用PAC文件时,我会出现以下错误:C# pac文件中的Web代理和错误,c#,proxy,httpwebrequest,C#,Proxy,Httpwebrequest,我的问题是关于使用pac文件和.net应用程序进行连接的问题 基本上我有一个HttpWebRequest和HttpWebResponse,当我创建一个HttpWebRequest时,因为我在一个代理后面,所以我必须使用代理连接到外部世界。因此,在我的代理设置中,我必须使用PAC文件来获得正确的地址,但当我使用PAC文件时,我会出现以下错误: {"The underlying connection was closed: An unexpected error occurred on a rece
{"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文件连接到internet
这是我的密码:
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...“您可以粘贴代理PAC脚本来检查语法吗?它是一个非常大的文件。。。它确实有效,因为它在所有公司中都被使用,比如它的代理问题。能否尝试连接到某个透明代理?如果在internet explorer中粘贴http://proxy文件,是否尝试下载该文件?。只需检查您的代理pac url是否正确是的,下载,顺便说一句,我用pac的短版本更新了帖子:)