Had the *exact* same issue last week! For golang how to use forward http proxy, env vars are hit or miss.
Here's a foolproof way:
```go
proxy, err := url.Parse("http://proxy:port")
if err != nil {
log.Fatal(err)
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxy),
TLSHandshakeTimeout: 10 * time.Second, // avoids hangs
},
}
```
Weird tip: if requests fail, try disabling HTTP/2 (`Transport.ForceAttemptHTTP2 = false`). Proxies can be finicky.
Here's a foolproof way:
```go
proxy, err := url.Parse("http://proxy:port")
if err != nil {
log.Fatal(err)
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxy),
TLSHandshakeTimeout: 10 * time.Second, // avoids hangs
},
}
```
Weird tip: if requests fail, try disabling HTTP/2 (`Transport.ForceAttemptHTTP2 = false`). Proxies can be finicky.
