如何在我的HTTP请求中使用带有身份验证的代理? [英] How to use proxies with authentication in my HTTP requests?
问题描述
我有一个代理IP地址(也需要用户名和密码).当我尝试使用它们访问网页时,会显示需要代理身份验证".
I have a proxy IP Address (that also require a username and password). When i try using them to visit webpages, i get "Proxy Authentication Required".
我发现了2016年的另一篇Stackoverflow帖子,并且该Github Issue已经关闭,但是他们没有提供任何有用的信息:
I'm found this other Stackoverflow post from 2016, and this Github Issue that was closed, but they don't provide anything useful:
- Proxy golang https
- https://github.com/golang/go/issues/22288
有什么建议吗?
看到了这篇文章:设置HTTP客户端的代理
Saw this post: Setting up proxy for HTTP client
有点差.但是,对于某些URL,我可以使用代理获得成功的响应,但是对于某些URL,则获得需要代理授权".
It's kinda close. However, for some urls I'm able to get a successful response using my proxy, but for certain urls, I get a "Proxy Authorization Required".
推荐答案
If you're following this authorized proxy tutorial, the additional step you would have to do is to set up the HEADER in the transport.
auth := "username:password"
basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
transport.ProxyConnectHeader = http.Header{}
transport.ProxyConnectHeader.Add("Proxy-Authorization", basicAuth)
这篇关于如何在我的HTTP请求中使用带有身份验证的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!