问题描述
我遇到了麻烦代理自动配置(PAC)在IE选项使用工作按预期净的WebRequest。
I'm having trouble getting Proxy Automatic Configuration (PAC) in IE options to work as expected using .Net WebRequest.
根据这篇文章:http://msdn.microsoft.com/en-gb/magazine/cc300743.aspx#S1该系统代理默认情况下应设置为每个WebRequest的。
According to this article: http://msdn.microsoft.com/en-gb/magazine/cc300743.aspx#S1The system proxy should be set by default with to each WebRequest.
这是怎么的proxy.js PAC文件是这样的:
That's how the proxy.js pac file looks like:
function FindProxyForURL(url, host)
{
return "PROXY ProxyServerName:3118; DIRECT;";
}
我也看了看这个帖子:How我应该设置默认代理使用默认凭据?
这表明添加此在App.config:
Which suggests to add this in the app.config:
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
添加这并没有帮助。
Adding this did not help.
我创建了一个小型控制台应用程序只是在这里测试了这一点。它是:
I created a small console application just to test this out.. here it is:
static void Main(string[] args)
{
HttpWebRequest request = null;
try
{
String resolvedAddress = WebRequest.DefaultWebProxy.GetProxy(new Uri("http://www.google.com")).ToString();
Console.WriteLine("Proxy for address is: " + resolvedAddress);
Uri m_URLToTest = new Uri("http://www.google.com");
request = WebRequest.Create(m_URLToTest) as HttpWebRequest;
request.Method = "GET";
request.KeepAlive = false;
request.Timeout = 5000;
request.Proxy = WebRequest.DefaultWebProxy;
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string message = reader.ReadToEnd();
}
catch (Exception ex)
{
Console.Write("Exception");
}
}
输出:代理服务器的地址是 http://www.google.com
The output:Proxy for address is http://www.google.com
而不是代理服务器的地址是ProxyServerName:3118
instead of Proxy for address is ProxyServerName:3118
它仅使用自动配置脚本时发生......
It happens only when using auto configuration script...
我错过了什么?请帮帮忙!
Did I miss anything? Please help!
推荐答案
找到了解决办法!
这是非常重要的PAC文件的MIME类型是:内容类型:应用程序/ x-NS-代理自动配置]
It is really important that the mime type of the PAC file would be: [Content-type: application/x-ns-proxy-autoconfig]
其他MIME类型可能无法正常工作。
Other mime types might not work.
请确保使用fiddler2(含禁用缓存)的MIME类型是合适的。有些配置可能显示的Content-Type:text / plain的是坏的。
Make sure using fiddler2 (with cache disabled) that the mime type is appropriate.Some configurations might show Content-Type: text/plain which is bad.
这篇关于从净IE设置使用代理服务器自动配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!