Ruby: Wie sende ich eine JSON-POST-Anfrage mit Curb?
Wie kann ich den Anforderungshauptteil einer CURB-Anforderung als meine json-Zeichenfolge festlegen? Ich versuche, eine JSON-POST-Anforderung mit Curb auszuführen.
Mein Code:
require 'rubygems'
require 'curb'
require 'json'
myarray = {}
myarray['key'] = 'value'
json_string = myarray.to_json()
c = Curl::Easy.http_post("https://example.com"
# how do I set json_string to be the request body?
) do |curl|
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.headers['Api-Version'] = '2.2'
end