My question is regarding the pac file and .net application to connect using it.
Basically I have an HttpWebRequest and HttpWebResponse, when I create an HttpWebRequest, because i'm behind a proxy i have to use proxy to connect to outside world. So in my proxy settings i have to use PAC file to obtain the correct adress, but when i use pac file i get a following error:
{"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."}
I'm sure it has something to do with a wrong use of PAC file, because for example if i take a proxy ip adress from a pac file i can connect, but of course i would like to use pac file as rule to connect to internet.
Here is my code:
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())
{
....
}
}
For request here is a short version of 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";
}
Any idea what do i miss?
Using a PacTester and surfing to some url i get the return of PROXY + ip, can it be cause of the return word PROXY? also the itp is not fully correct path not like "http://ip..."