Convert curl to coldfusion cfhttp

I have a curl 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 tried converting it to coldfusion, but the server hit me with a 406 error. I tried to quit whatever I can think of about this problem, but can't get it to work. Any help is appreciated! Here 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>

      

+3


source to share


1 answer


(From comments)

For some laughs, trying to add an Accept header to the cfhttp call. I saw somewhere that the default curl can add a title to all the accept: Accept: */*

. Based on a 406 error code that may be relevant here.

406 Not Acceptable
The requested resource is able to generate content that is not acceptable according to the Accept headers sent in the request.

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



Update:

CraigL confirmed in the comments that adding an "Accept" title resolved the issue. Here's the complete code to make the solution 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>

      

+2


source







All Articles