Connection Failure using CFHTTP

Scenario:

Attempting to download and parse an XML feed using CFHTTP Get request. The url is not SSL enabled and uses IIS.

 

Problem:

A StatusCode of 200 OK is returned but the FileContents returns Connection Failure.

 

Analysis:

The header response contains the following header:

IISExport: This web site was exported using IIS Export v4.2

 

Resolution:

Thanks to an old post by Steven Erat which can be found here the solution is quite simple. It seems that ColdFusion cannot, by default, handle HTTP Compression. To get this to work you have to request the file be deflated using the Accept-Encoding and TE headers:

 
<cfhttp url="#variables.feedURL#">
     <cfhttpparam type="Header" name="Accept-Encoding"
                                            value="deflate;q=0" />
     <cfhttpparam type="Header" name="TE" value="deflate;q=0" />
</cfhttp>
 

This basically asks the webserver to send an uncompressed response which will solve the problem. From Steven's post, you may have to change the deflate;q=0 to * in the Accept-Encoding header to get it to work on occasion. I've not had this problem though.

It is interesting that Steven's post is almost 5 years old and I'm just coming across this problem for the first time even though I've done quite a bit of work with remote XML feeds.

Related Posts

This entry was posted in ColdFusion, IIS, Programming and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.