gpt4 book ai didi

proxy - 如何在代理后面使用 httpotion?

转载 作者:行者123 更新时间:2023-12-04 17:08:47 25 4
gpt4 key购买 nike

(编辑:我通过使用 HTTPoison 的 get! 函数清除了这个问题。

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

我是使用 Elixir 的新手。我在 httpotion 上尝试了示例应用程序作为第一步。

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



但是,它无法访问代理后面的站点。
iex(1)> res = HTTPotion.get "httpbin.org/get"
** (HTTPotion.HTTPError) nxdomain
(httpotion) lib/httpotion.ex:195: HTTPotion.handle_response/1

没有代理,它可以像这样成功地工作;
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",...

我试图通过阅读 httpotion 所依赖的 ibrowse 来设置代理参数,比如;
req = HTTPotion.get("httpbin.org/get", [{:proxy_host, "proxy.mydomain.com"}, {:proxy_port, 8080}])

但结果是一样的。

如何设置httpotion的代理参数?或者在 elixir 上是否有任何可以处理代理的 HTTP 访问替代库?

我的环境是 Ubuntu 14.04.2,环境变量(http_proxy、https_proxy、HTTP_PROXY 和 HTTPS_PROXY)设置正确。

最佳答案

看看httpoison tests :D

以下是使用代理执行 get 请求的方法:

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

关于proxy - 如何在代理后面使用 httpotion?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30272263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com