首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过https使用Typhoeus::Request对象

如何通过https使用Typhoeus::Request对象
EN

Stack Overflow用户
提问于 2019-04-27 10:42:34
回答 1查看 756关注 0票数 0

我尝试使用Typhoeus::Request对象发出https请求,但无法正常工作。

我正在运行的代码是这样的:

代码语言:javascript
复制
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

我得到的回应是:

代码语言:javascript
复制
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

为什么会发生这种情况?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-27 16:58:18

这很难知道,因为你的例子不是一个可达的url。但我看到的两件事是,您没有传递ssl证书或密钥。但也有302表示重定向。你可以尝试重定向,但是你的第一个问题可能是你不需要设置SSL选项,为什么呢?

如果您尝试以下选项,请查看:

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55876797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档