pac文件中的Web代理和错误

时间:2012-12-05 07:51:56

标签: c# proxy httpwebrequest

我的问题是关于使用它连接的pac文件和.net应用程序。

基本上我有一个HttpWebRequest和HttpWebResponse,当我创建一个HttpWebRequest时,因为我在代理后面,我必须使用代理连接到外部世界。因此,在我的代理设置中,我必须使用PAC文件来获取正确的地址,但是当我使用pac文件时,我收到以下错误:

{"The underlying connection was closed: An unexpected error occurred on a receive."}

的InnerException:

{"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并浏览一些网址我得到了PROXY + ip的返回,这可能是返回单词PROXY的原因吗? itp也不是完全正确的路径,不像" http://ip..."

0 个答案:

没有答案