在發(fā)出 HTTP 請(qǐng)求時(shí),Go 是否有某種方式使用 DefaultNetworkCredenti
我正在編寫一個(gè)簡(jiǎn)單的 Go 實(shí)用程序,該實(shí)用程序向 Internet 發(fā)出一些 POST 請(qǐng)求,但我需要通過代理并在不知道用戶憑據(jù)的情況下使用 NTLM。我見過如下 CSharp 代碼:wc = new CookieWebClient();wc.UseDefaultCredentials = true;wc.Proxy = WebRequest.DefaultWebProxy;wc.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;在 Go 中,我設(shè)法確定了系統(tǒng)代理,感覺就像是 hack:import ( "net/http" "net/url" "strings" "golang.org/x/sys/windows/registry")func getSystemProxy() func(req *http.Request) (*url.URL, error) { var e error var k registry.Key var proxy *url.URL var v string // Open the "Internet Settings" registry key k, e = registry.OpenKey( registry.CURRENT_USER, strings.Join( []string{ "Software", "Microsoft", "Windows", "CurrentVersion", "Internet Settings", }, "\\", ), registry.QUERY_VALUE, ) if e != nil { return http.ProxyFromEnvironment } defer k.Close() // Read the "ProxyServer" value v, _, e = k.GetStringValue("ProxyServer") if (e != nil) || (v == "") { return http.ProxyFromEnvironment } // Get the http= portion and fix it up v = strings.Split(v, ";")[0] v = strings.Replace(v, "=", "://", 1) // Parse url if proxy, e = url.Parse(v); e != nil { return http.ProxyFromEnvironment } return http.ProxyURL(proxy)}我一直無(wú)法找到與 CSharp 的https://docs.microsoft.com/en-us/dotnet/api/system.net.credentialcache.defaultnetworkcredentials?view=netcore-3.1等效的 Go 。我找到了https://github.com/Azure/go-ntlmssp但這需要我對(duì)我沒有的用戶憑據(jù)進(jìn)行硬編碼,并且我需要為每個(gè)用戶編譯一個(gè)新的二進(jìn)制文件,我會(huì)這樣做不想做。我正在尋找 0 配置解決方案。我希望這盡可能動(dòng)態(tài)。如果 CSharp 能做到,為什么 Go 不能呢?
查看完整描述