如何将抑制请求的请求正文设置为我的json字符串?我正在尝试使用Curb做一个JSON POST请求。
我的代码:
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发布于 2010-10-04 08:27:24
正确的做法是在URL后面添加内容:
c = Curl::Easy.http_post("https://example.com", json_string_goes_here
) do |curl|
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.headers['Api-Version'] = '2.2'
end这会将json_string设置为请求正文。
https://stackoverflow.com/questions/3851445
复制相似问题