使用ColdFusion,我正在尝试将JSON POST到API。这是我到目前为止的代码 -
<cfhttp url="#url#" method="post" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(jsonStr)#">
</cfhttp>
JSON的一个例子就在这里 -
{
"booking":{
"username" : "#username#",
"password" : "#password#",
"customerEmail" : "#customer_email_address#",
"firstName" : "#customer_firstname#",
"lastName" : "#customer_surname#",
"telephoneNumber" : "#customer_mobile_number#",
"guestNumber" : #url.guests#,
"unitNumber" : #url.location#,
"eventDate" : "#LSDateFormat(url.when,'dd/mm/yyyy')#"
}
}
当我使用Chrome中的POSTMAN客户端将此JSON传递给API URL时,一切都很好!但是当我在CF中处理这个时,我只是从API中得到一个错误的请求错误。我意识到消息是没有用的,简单的是在API中设置。
如果我从Chrome中的POSTMAN客户端删除内容类型,我会收到相同的消息。所以我“假设”内容类型没有被发送或以某种方式在CF中写过。
有人能指出我正确的方向吗?
由于
答案 0 :(得分:1)
问题是API不接受我认为需要的内容。