我提出以下API GET請求,使用Ruby 1.9.3和httparty寶石解碼請求作爲有效的JSON:無法使用Ruby
uri= HTTParty.post("www.surveys.com/api/v2/contacts",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' },
:body => {
"custom_test" => test,
"name" => firstname,
"email" => emailaddress
}
)
變量auth
,test
,firstname
,和emailaddress
有效。這是我從我的請求中收到的回覆:
{
"code": "invalid_json",
"description": "Request sent with Content-Type: application/json but was unable to decode request body as valid json.",
"success": false
}
500
#<Net::HTTPInternalServerError:0x007fe4eb98bde0>
發佈此JSON請求的方式有什麼問題?
編輯:它可能值得注意的是,API允許你定義一個聯繫人的自定義屬性,因此正文中的「custom_test」屬性。
確定的API是不扔的是因爲它缺少在請求一些片非可選的數據?您應該嘗試將其發佈到本地Web服務器並捕獲輸出,因爲您的代碼對我來說看起來是正確的。 –