[英]HTTParty not sending data to API
I am trying to call a Restful API (basically a third party application). 我正在尝试调用Restful API(基本上是第三方应用程序)。 Here is my code:
这是我的代码:
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" }
})
This is returning a response with status "200 ok". 这将返回状态为“ 200 ok”的响应。 But I am not able to find the changes in my third party application.
但是我无法在第三方应用程序中找到更改。
I tried with "Rest-client" and "Net-http" as well. 我也尝试过“ Rest-client”和“ Net-http”。 Both of them are also not working.
他们两个也不工作。
Thanks for helping in advance. 感谢您的提前帮助。
I assume that by 我认为
"not able to find the changes in my third party application"
“无法在我的第三方应用程序中找到更改”
, you mean that your not able to hit that third party url. ,表示您无法访问该第三方网址。
Solution: 解:
You don't need to wrap the query and headers into a hash. 您无需将查询和标头包装到哈希中。 Simply pass them as parameters like:
只需将它们作为参数传递即可:
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"
}
)
This works for me. 这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.