0

Using ColdFusion, I am trying to POST JSON to an API. Here is the code I have so far -

<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>

An example of the JSON is here -

{
  "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')#"
   }
 }

When I pass this JSON to the API URL with POSTMAN client in Chrome, everything is good! however when I process this in CF, I simply get a bad request error from the API. I realise that message is no use that is simple whats being set in the API.

If I remove the content-type from POSTMAN client in Chrome, I get the same message. So I am "assuming" That the content-type is not being sent or over written somehow in CF.

Can anyone point me in the right direction?

Thanks

4

1 回答 1

1

Issue was with the API not accepting what I thought it required.

于 2013-06-25T21:49:47.990 回答