获取HTTPS响应 [英] Get HTTPS response
本文介绍了获取HTTPS响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这很好用:
require 'net/http'
uri = URI('http://api.twitter.com/1/statuses/user_timeline.json')
args = {include_entities: 0, include_rts: 0, screen_name: 'johndoe', count: 2, trim_user: 1}
uri.query = URI.encode_www_form(args)
resp = Net::HTTP.get_response(uri)
puts resp.body
但是从 http
更改为 https
会导致无意义错误。我不是在问为什么错误毫无意义,我只想知道 get_response
对于 https $ c $的最接近的方法是什么c>?
But changing from http
to https
leads to a meaningless error. I'm not asking why the error is meaningless, I would just like to know what's the closest means of doing get_response
for https
?
我在 Net :: HTTP doc但它看起来不是很令人印象深刻,它会让我从参数hash手动编写URL - 没有用。
I've seen the 'HTTPS' example in the Net::HTTP doc but it looks not very impressive and will make me manually compose the URL from my parameters hash - no good.
推荐答案
这是一个适用于Ruby 1.9.3的示例
Here is a example which works for me under Ruby 1.9.3
require "net/http"
uri = URI.parse("https://api.twitter.com/1/statuses/user_timeline.json")
args = {include_entities: 0, include_rts: 0, screen_name: 'johndoe', count: 2, trim_user: 1}
uri.query = URI.encode_www_form(args)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.body
这篇关于获取HTTPS响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文