Tuesday, January 13, 2015

ColdFusion CFHTTP analogous to CURL

* This is a continuously updated post on the corresponding CFHTTP syntax for CURL. If you need help, send me a message and I will try to help.

I have been trying to integrate different APIs with ColdFusion/Railo recently and the difficult part is of course to understand the way the API is expecting data. Mostly they 3rd party will provide library or code for PHP and .NET, but not for ColdFusion. In some cases they provide the CURL syntax. I thought I will scribble my findings here so that it is useful for someone to write CFHTTP by seeing the CURL syntax.

File Upload 
  1. to post a file to the folder /upload to the server. The URL is http://app.prasanthkumars.com/upload
  2. the API uses Basic Authorization
  3. File name is test.png

curl -f file=@test.png "http://username:password@app.prasanthkumars.com/upload"

<cfset credentials = tobase64("#username#:#password#")>

<cfhttp method="POST" url="http://app.prasanthkumars.com/upload" result="upload_result">
     <cfhttpparam type="header" name="Authorization" value="Basic #credentials#"/>
     <cfhttpparam file="c:\test.png" type="file" name="file" mimetype="image/png">