3

I have a curl call that works like a charm:

curl -X POST -H 'Content-Type: application/xml' -H "X-ApiVersion: 1.0" -H "X-AccessToken: [api-token]" -d '[xml]' https://www.API.com

I've tried to convert it to coldfusion, but the server kicks back a 406 error on me. I've tried throwing everything I can think of at this problem, but can't get it to work. Any help is appreciated! Here's the CF:

<cfhttp url="#APIURL#" method="POST" result="activity">
    <cfhttpparam type="header" name="Content-Type" value="application/xml">
    <cfhttpparam type="header" name="X-AccessToken" value="#accesstoken#" />
    <cfhttpparam type="header" name="X-ApiVersion" value="1.0" />   
    <cfhttpparam type="body" encoded="false" value="#trim(request.xml)#" />
</cfhttp>
Craig L
  • 63
  • 1
  • 7
  • Is it worth mentioning the `url` value is lacking a closing pound sign? – TRose Jul 16 '15 at 20:08
  • ha, nice catch! but no, that was just a quick hack to hide the real url and token. – Craig L Jul 16 '15 at 20:11
  • 1
    I do not see anything obviously wrong. Try some low tech debugging. Create a test page on your CF server that dumps the request [`GetHTTPRequestData()`](https://wikidocs.adobe.com/wiki/display/coldfusionen/GetHttpRequestData). Call that page from both curl and cfhttp and see what is different about the requests. – Leigh Jul 16 '15 at 21:03
  • 2
    For grins, trying adding an "Accept" header to cfhttp. I saw somewhere that curl may add an Accept: */* header. Based on the error code, that might be relevant here. If not, your best bet is to look at the raw request dumps (as suggested above) and see what is different. – Leigh Jul 16 '15 at 21:37
  • Crud... I forgot SO interprets asterisk as italics. That should have read: `Accept: */*`. – Leigh Jul 16 '15 at 23:19
  • 1
    Try `` instead of `` – John Whish Jul 17 '15 at 11:42
  • 1
    SOLVED! Thanks to Leigh! did the trick. Thanks to all that answered! – Craig L Jul 17 '15 at 20:16

1 Answers1

2

(From the comments)

For grins, trying adding an "Accept" header to the cfhttp call. I saw somewhere that curl may add an accept all header by default: Accept: */*. Based on the 406 error code, that might be relevant here.

406 Not Acceptable
The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.

If not, your best bet is to look at the raw request dumps (as suggested above) and see what is different.

Update:

CraigL confirmed in the comments that adding an "Accept" all header resolved the issue. Posting the full code here so the solution is more visible:

<cfhttp url="#APIURL#" method="POST" result="activity">
    <cfhttpparam type="header" name="Content-Type" value="application/xml">
    <cfhttpparam type="header" name="X-AccessToken" value="#accesstoken#" />
    <cfhttpparam type="header" name="X-ApiVersion" value="1.0" />   
    <cfhttpparam type="header" name="Accept" value="*/*"> 
    <cfhttpparam type="body" encoded="false" value="#trim(request.xml)#" />
</cfhttp>
Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103