如何使用https使用Typhoeus :: Request对象

问题描述 投票:1回答:1

我正在尝试使用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

为什么会这样?

ruby http ssl https typhoeus
1个回答
1
投票

嗯,这很难知道,因为你的例子不是一个可达的网址。但我看到的两件事是你没有传递证书或密钥。但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

© www.soinside.com 2019 - 2024. All rights reserved.