How to use proxies with authentication in my HTTP requests?

余生长醉 提交于 2019-12-09 13:01:28

问题


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".

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

Any suggestions?

EDIT: Saw this post: Setting up proxy for HTTP client

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".


回答1:


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)



回答2:


to add authorization, you may need to add a header:

auth := "{user}:{password}"
basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
request.Header.Add("Proxy-Authorization", basicAuth)


来源:https://stackoverflow.com/questions/53406874/how-to-use-proxies-with-authentication-in-my-http-requests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!