-
How will the code look like if I want to go through a Proxy: curl --proxy "proxyhost:8888" --cacert mitmproxy-ca-cert.cer "https://example.com" |
Beta Was this translation helpful? Give feedback.
Answered by
aphsa
Dec 19, 2024
Replies: 2 comments 1 reply
-
You would need to change the |
Beta Was this translation helpful? Give feedback.
0 replies
-
I end up using this method. Is there a better solution? // custom HTTP transport if proxy is enabled
var transport *http.Transport
if config.Proxy {
transport = &http.Transport{
Proxy: http.ProxyURL(&url.URL{
Scheme: "http",
Host: config.Proxyhostport,
}),
TLSClientConfig: tlsConfig,
}
}
// custom HTTP client with timeout
client := &http.Client{
Timeout: 15 * time.Second,
}
if config.Proxy {
client.Transport = transport
}
// Fetch the response
var body string
err := requests.
URL(config.URL).
Header("Authorization", fmt.Sprintf("Bearer %s", config.APIKey)).
Client(client).
ToString(&body).
Fetch(context.Background())
if err != nil {
return result, fmt.Errorf("failed to perform request: %w", err)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
earthboundkid
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I end up using this method. Is there a better solution?