我正在尝试使用https
对象发出Typhoeus::Request
请求,但无法正常工作。
我正在运行的代码是这样的:
url = "https://some.server.com/"
req_opts = {
:method => :get,
:headers => {
"Content-Type"=>"application/json",
"Accept"=>"application/json"
},
:params=>{},
:params_encoding=>nil,
:timeout=>0,
:ssl_verifypeer=>true,
:ssl_verifyhost=>2,
:sslcert=>nil,
:sslkey=>nil,
:verbose=>true
}
request = Typhoeus::Request.new(url, req_opts)
response = request.run
我得到的答复是:
HTTP/1.1 302 Found
Location: https://some.server.com:443/
Date: Sat, 27 Apr 2019 02:25:05 GMT
Content-Length: 5
Content-Type: text/plain; charset=utf-8
为什么会这样?
答案 0 :(得分:1)
很难知道,因为您的示例不是可访问的URL。但是我看到的两件事是您没有通过ssl证书或密钥。但是302也指示重定向。您可以尝试遵循重定向,但是您的第一个问题可能是您不需要设置SSL选项,为什么呢?
查看是否尝试以下选项:
req_opts = {
:method => :get,
:headers => {
"Content-Type"=>"application/json",
"Accept"=>"application/json"
},
:params=>{},
:params_encoding=>nil,
:timeout=>0,
:followlocation => true,
:ssl_verifypeer=>false,
:ssl_verifyhost=>0,
:verbose=>true
}
有关详细信息,请参见以下各节
https://github.com/typhoeus/typhoeus#following-redirections https://github.com/typhoeus/typhoeus#ssl