简体   繁体   中英

How to set a proxy api token as auth on hackney through HTTPoison?

I'm having a problem authenticating on Crawlera service using HTTPoison.

The crawlera's API documentation says I only need the API Token.

ie curl -vx proxy.crawlera.com:8010 -U <API key>: http://httpbin.org/ip

So, I'm having problems setting the authentication options on HTTPoison settings.

I'm trying this 3 options:

HTTPoison.get("url", header, hackney: [:insecure], proxy: 'proxy.crawlera.com:8010', proxy_auth: 'api-token') Error -> (FunctionClauseError) no function clause matching in :hackney.do_connect/7

HTTPoison.get("url", header, hackney: [:insecure], proxy: 'proxy.crawlera.com:8010', proxy_auth: {'api-token',''}) Error -> (ArgumentError) argument error :erlang.bit_size([])

HTTPoison.get("url", header, hackney: [:insecure], proxy: 'api-token:@proxy.crawlera.com:8010') Error -> {"X-Crawlera-Error", "bad_proxy_auth"}

If someone knows how to set correctly the parameters I'll appreciate the help.

  1. The proxy argument should be a tuple of the host and port.
  2. You need to use binaries instead of charlists for the host and both the elements of proxy_auth .

The following should work:

proxy: {"proxy.crawlera.com", 8010}, proxy_auth: {"api-token", ""}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM