我尝试使用Typhoeus::Request对象发出https请求,但无法正常工作。
我正在运行的代码是这样的:
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为什么会发生这种情况?
发布于 2019-04-27 16:58:18
这很难知道,因为你的例子不是一个可达的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
https://stackoverflow.com/questions/55876797
复制相似问题