这适用于(在ubuntu上):
curl -v -g 'https://example.com/api/path/to/service?json={"select":["cats","dogs","cows"],"from":"20170115","to":"20170117"}'
这也有效(红宝石):
require 'rest-client'
resource = RestClient::Resource.new(
'https://example.com/api/path/to/service?json={"select":["cats","dogs","cows"],"from":"20170115","to":"20170117"}')
resp = resource.get
但是,我想拆分请求主机和正文(在ruby中)。
我试过了:
require 'rest-client'
resource = RestClient::Resource.new(
'https://example.com/api/path/to/service')
resp = resource.get(:data => 'json={"select":["cats","dogs","cows"],"from":"20170115","to":"20170117"}', :content_type => :json, :accept => :json)
但服务器返回:
# => 400 BadRequest | application/json 49 bytes
No such encoding: "utf8"
以及这种变化:
resp = resource.get(:json => '{"select":["cats","dogs","cows"],"from":"20170115","to":"20170117"}', :content_type => :json, :accept => :json)
与:payload =>
相当,但得到的错误结果相同。
我看起来stackoverflow很薄,但我尝试的任何东西似乎都没有用。我觉得这是红宝石在发送之前逃避双引号的方式 - 只是一个猜测。
有什么想法吗?
非常感谢所有帮助。即使链接到正确的stackoverflow答案: - )
感谢。