我正在尝试调用Restful API (基本上是第三方应用程序)。下面是我的代码:
resp = HTTParty.post("http://example.com/test/api/url",
{
:query => {"id"=> 3, "example_payload"=> "test payload", "details"=> {}},
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'client_key' => "xxx-xxx-xxxxx" }
})这将返回一个状态为“200ok”的响应。但是我无法在我的第三方应用程序中找到这些更改。
我也尝试过"Rest-client“和"Net-http”。这两种方法也不起作用。
感谢您提前提供帮助。
发布于 2015-07-16 22:43:30
我假设通过
“无法在我的第三方应用程序中找到更改”
,你的意思是你不能点击第三方的网址。
解决方案:
您不需要将查询和标头包装到一个散列中。只需将它们作为参数传递,如下所示:
HTTParty.post(
"http://example.com/test/api/url",
query: {"id"=> 3, "example_payload"=> "test payload", "details"=> {}},
headers: { 'Content-Type' => 'application/json',
'Accept' => 'application/json',
'client_key' => "xxx-xxx-xxxxx"
}
)这对我很有效。
https://stackoverflow.com/questions/31455655
复制相似问题