I'm trying to use proxies with the net/http package. My proxy is a rotating proxy with a Username, password, Proxy address and a port.
I tried setting it as an environment variable using os.setEnv()
as well as adding it in my windows 10 env variables but turns out maybe windows does not support user-pass authenticated proxies.
I tried the http transport method too but could not get it to work
func SetProxy() *http.Client {
cfg := GetConfig()
if cfg.UseProxy {
proxyUrl, err := url.Parse("http://" cfg.Proxy)
if err != nil {
panic(err)
}
myClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
return myClient
}
return &http.Client{}
}
Please if someone could point me to a tutorial or some documentation to use proxies specifically proxies with user-pass auth!
note: I used this format everywhere: username:password@proxyaddress:port
CodePudding user response:
As a debug attempt, you can print the client.Transport.Proxy
function; if it's not nil, call it and print what it returns. If Proxy
is not nil
and returns not nil
*URL
, then proxy IS used.