简体   繁体   English

如何通过HTTPoison在hackney上将代理api令牌设置为auth?

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

I'm having a problem authenticating on Crawlera service using HTTPoison. 我在使用HTTPoison对Crawlera服务进行身份验证时遇到问题。

The crawlera's API documentation says I only need the API Token. crawlera的API文档说,我只需要API令牌。

ie curl -vx proxy.crawlera.com:8010 -U <API key>: http://httpbin.org/ip 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. 因此,我在设置HTTPoison设置上的身份验证选项时遇到问题。

I'm trying this 3 options: 我正在尝试这3个选项:

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')错误-> (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: 'proxy.crawlera.com:8010', proxy_auth: {'api-token',''})错误-> (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"} HTTPoison.get("url", header, hackney: [:insecure], proxy: 'api-token:@proxy.crawlera.com:8010')错误-> {"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. proxy参数应该是主机和端口的元组。
  2. You need to use binaries instead of charlists for the host and both the elements of proxy_auth . 您需要对主机和proxy_auth两个元素都使用二进制文件而不是proxy_auth

The following should work: 以下应该工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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