How can I use httpotion behind a proxy server?

(Edit: I cleared this problem using HTTPoison get! Function.

HTTPoison.start HTTPoison.get!("httpbin.org/get", [], [{:proxy, {"proxy.mydomain.com", 8080}}]) 

I am new to using Elixir. I tried an example application on httpotion as a first step.

iex> response = HTTPotion.get "httpbin.org/get"

However, he could not get to the site for a proxy.

 iex(1)> res = HTTPotion.get "httpbin.org/get" ** (HTTPotion.HTTPError) nxdomain (httpotion) lib/httpotion.ex:195: HTTPotion.handle_response/1 

Without a proxy, it successfully works as follows:

 iex(1)> res = HTTPotion.get "httpbin.org/get" %HTTPotion.Response{body: "{\n \"args\": {}, \n \"headers\": {\n \"Content-Length\": \"0\", \n \"Host\": \"httpbin.org\"\n }, \n \"origin\": \"191.238.84.51\", \n \"url\": \"http://httpbin.org/get\"\n}\n", headers: ["Access-Control-Allow-Credentials": "true",... 

I tried to set proxy settings by reading ibrowse, which httpotion depends on, for example:

 req = HTTPotion.get("httpbin.org/get", [{:proxy_host, "proxy.mydomain.com"}, {:proxy_port, 8080}]) 

But the result is the same.

How to set proxy settings for httpotion? Or is there an elixir replacement library for HTTP access that can handle proxies?

My environment is Ubuntu 14.04.2, and the environment variables (http_proxy, https_proxy, HTTP_PROXY, and HTTPS_PROXY) are set correctly.

+5
source share
2 answers

Take a look at httpoison tests : D

this is how you execute get request with proxy:

 HTTPoison.get!("http://www.google.com", [], [{:proxy, "proxy.company.address:port"}]) 
+9
source

I just figured this out while reading the source, but now I notice that it is documented in the latest README ...

The short version (since this answer appeared earlier in Google search than in README) you need to pass the parameters directly to ibrowse, you do this using the parameter: ibrowse, and then note that ibrowse usually uses character lists

So an example:

 HTTPotion.get "httpbin.org/get", [ ibrowse: [ proxy_host: 'some.host', proxy_port: 8080 ] ] 

Note that httpotion does not seem to catch exceptions too much, not "!". function versions ... Failure to use char lists or the like will result in all kinds of difficult to understand exceptions ...

+2
source

All Articles