我正在运行一个简单的Sinatra应用程序,我需要在其中查询一些数据并通过JSON将POST发送到webhook URL进行处理。我不确定如何正确格式化我为 HTTParty 检索到的记录。
联系人正在打印到/帐户/{account_id}/contacts.json,我想要他们,他们的数据只是没有成功发送。
app.rb
get "/account/:account_id/contacts.json" do
@contacts = Contact.where("sfid = ?", params[:account_id])
HTTParty.post("https://hooks.webapp.com/hooks/catch/387409/1us4j3/",
{
:body => [ @contacts ].to_json,
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
})
@contacts.to_json
end
似乎错误是
2.3.1/lib/ruby/2.3.0/net/http/generic_request.rb:183:in 'send_request_with_body'
它在您的请求中找不到任何正文。您正在哈希中发送参数正文和头部。
试试这个:
get "/account/:account_id/contacts.json" do
@contacts = Contact.where("sfid = ?", params[:account_id])
HTTParty.post("https://hooks.webapp.com/hooks/catch/387409/1us4j3/",
:body => @contacts.to_json,
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
)
@contacts.to_json
end
您也可以在此处查看有关HTTP帖子的更多信息
希望这有帮助..