将 curl PUT 转换为 ruby net:http
convert curl PUT to ruby net:http
我在整个互联网上搜索并通读了 https://ruby-doc.org/stdlib-2.4.2/libdoc/net/http/rdoc/Net/HTTP.html
我仍然无法获得将以下 curl 命令转换为 ruby 的正确语法。我会把我尝试过的所有不同方法都告诉你。有人可以给我一个例子,说明在 Ruby 中应该是什么样子吗?
curl -k -s -H "Accept: application/json" -H "Content-Type:application/json" -X PUT --data '{"name": "anonymous", "password": "obfuscated"}' https://some.domain/repository/npm/-/user/org.couchdb.user:anonymous
我看到的所有示例都是 POST 而不是 PUT
通过 Postman 转换。
require 'uri'
require 'net/http'
url = URI("https://some.domain/repository/npm/-/user/org.couchdb.user:anonymous")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Put.new(url)
request["Accept"] = 'application/json'
request["Content-Type"] = 'application/json'
request["Cache-Control"] = 'no-cache'
request["Postman-Token"] = '9e3622cd-fda5-458d-2521-325849546ef7'
request.body = "{\"name\": \"anonymous\", \"password\": \"obfuscated\"}"
response = http.request(request)
puts response.read_body
我在整个互联网上搜索并通读了 https://ruby-doc.org/stdlib-2.4.2/libdoc/net/http/rdoc/Net/HTTP.html
我仍然无法获得将以下 curl 命令转换为 ruby 的正确语法。我会把我尝试过的所有不同方法都告诉你。有人可以给我一个例子,说明在 Ruby 中应该是什么样子吗?
curl -k -s -H "Accept: application/json" -H "Content-Type:application/json" -X PUT --data '{"name": "anonymous", "password": "obfuscated"}' https://some.domain/repository/npm/-/user/org.couchdb.user:anonymous
我看到的所有示例都是 POST 而不是 PUT
通过 Postman 转换。
require 'uri'
require 'net/http'
url = URI("https://some.domain/repository/npm/-/user/org.couchdb.user:anonymous")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Put.new(url)
request["Accept"] = 'application/json'
request["Content-Type"] = 'application/json'
request["Cache-Control"] = 'no-cache'
request["Postman-Token"] = '9e3622cd-fda5-458d-2521-325849546ef7'
request.body = "{\"name\": \"anonymous\", \"password\": \"obfuscated\"}"
response = http.request(request)
puts response.read_body