使用Internet Explorer代理设置

huangapple go评论77阅读模式
英文:

Use Internet explorer proxy settings

问题

我正在开发一个需要连接到互联网的Go应用程序。我使用http.ProxyFromEnvironment传输方式来自动检测Linux上的代理,但在Windows上效果不佳。

我该如何获取Internet Explorer的代理设置?

英文:

I'm developing a go application that need to connect to the internet. I use the http.ProxyFromEnvironment transport to auto-detect the proxy on linux, but it falls short on windows.

How can I retrieve the proxy settings of Internet Explorer?

答案1

得分: 1

这些值可以在注册表中找到:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

这是一个简单的库,可以方便地检索这些设置(免责声明:最近我重新编写了这个库):https://godoc.org/github.com/mattn/go-ieproxy

你可以在init函数中调用OverrideEnvWithStaticProxy(),以便透明地使用http.ProxyFromEnvironment

func init() {
    ieproxy.OverrideEnvWithStaticProxy()
    http.DefaultTransport.(*http.Transport).Proxy = http.ProxyFromEnvironment
}
英文:

Those values can be found in the registry: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings.

Here is a simple library that allows you to retrieve those settings easily (disclaimer: I re-wrote most of this library recently): https://godoc.org/github.com/mattn/go-ieproxy

You can transparently use http.ProxyFromEnvironment by calling OverrideEnvWithStaticProxy() in an init function:

func init() {
	ieproxy.OverrideEnvWithStaticProxy()
	http.DefaultTransport.(*http.Transport).Proxy = http.ProxyFromEnvironment
}

huangapple
  • 本文由 发表于 2017年1月20日 21:15:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/41764614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定