2

net/http有没有办法使用or来创建匿名(公共或私人)要点net/https

4

2 回答 2

4

这对我有用。

require 'net/http'
require 'json'

uri = URI("https://api.github.com/gists")

payload = {
  'description' => "My test gist",
  'public' => true,
  'files' => {
    'test.txt' => {
      'content' => "This is a test!\n\nI am making a public gist."
    }
  }
}

req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json

puts req.inspect
puts req.body.inspect

# GitHub API is strictly via HTTPS, so SSL is mandatory
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
  http.request(req)
end

puts res.inspect
puts res.body.inspect

结果:我的测试要点

于 2013-05-03T19:26:38.450 回答
0

这个 gem 将为您解决问题https://github.com/defunkt/gist

作为记录,它确实需要 net/https。

于 2013-05-03T18:45:42.253 回答