我想使用Ruby httpclient来发出请求。我试图实现这个代码:
def submit!
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = HTTPClient.new(url)
request.basic_auth('username', 'pass')
request['content-type'] = 'application/xml'
request['cache-control'] = 'no-cache'
request.body = request_body
response = http.request(request).body
response = Response.new(response)
check_for_approved_response(response)
response
end
但我得到错误:
unsupported proxy https://staging.gate.some_address.net/process/3ab20f2ddbe78ab8be9f5a9645c1010330dc868f
你能推荐一些解决方法吗?
答案 0 :(得分:0)
确保ruby可以查看和阅读/etc/resolv.conf并且您没有设置HTTP_PROXY env变量。还要检查你的ssl是否使用非标准的ssl端口。
答案 1 :(得分:0)
在终端上运行echo $ HTTP_PROXY。如果你看到任何价值,那就不好了。你必须取消设置该变量。
请参阅 - https://github.com/savonrb/savon/issues/123#issuecomment-620825
答案 2 :(得分:0)
https://www.rubydoc.info/gems/httpclient/2.1.5.2/HTTPClient
通过HTTP代理访问资源。您可以改用环境变量“ http_proxy”或“ HTTP_PROXY”。
clnt = HTTPClient.new('http://myproxy:8080')
因此,在您的代码request = HTTPClient.new(url)
中,将目标URL作为HTTPClient的代理。 (当您来自net / http时,确实确实有点令人困惑)