有没有办法使用net/http
或net/https
创建匿名(公共或私人)要点?
答案 0 :(得分:2)
这对我有用。
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
结果:My test gist
答案 1 :(得分:0)
这个宝石会为你做https://github.com/defunkt/gist!
对于记录,它确实需要net / https。