edgurgel / httpoison

Yet Another HTTP client for Elixir powered by hackney
https://hex.pm/packages/httpoison
MIT License
2.22k stars 339 forks source link

Proxy option not working #462

Open shellking4 opened 1 year ago

shellking4 commented 1 year ago

I have this curl request

curl -x "http://proxy-server.com:8001" -k "https://httpbin.org/ip"

The curl request is actually going through the proxy server and I'm getting at each hit a new ip address.

But when I try with HTTPoison it's not working as expected.

I tried these codes

HTTPoison.get!("https://www.httpbin.org/ip", [], [proxy: {"http://proxy-server.com"}])

HTTPoison.get!("https://www.httpbin.org/ip", [], [{:proxy, "http://proxy-server.com"}])

What am I doing wrong ?

ShahneRodgers commented 1 year ago

I think HTTPoison.get!("https://www.httpbin.org/ip", [], [proxy: "http://proxy-server.com:8001"]) or HTTPoison.get!("http://www.httpbin.org/ip", [], [{:proxy, {"proxy-server.com", 8001}}]) should work.

As per the docs

:proxy - a proxy to be used for the request; it can be a regular url or a {Host, Port} tuple, or a {:socks5, ProxyHost, ProxyPort} tuple

So the issue with the first form is that you're giving it a tuple without splitting up the host / port part. The second isn't working because you haven't specified a port and HTTP defaults to port 80, not the port 8001 that you've told curl to use.