Error 'Content is not allowed in prolog.' trying to CFHTTP api

Can you help?

If I run this URL: (with real appid) in a web browser ... it works).
BUT if I run the URL through CFHTTP GET (see code below) ... I get this error:

An error occured while Parsing an XML document.
: 'Content is not allowed in prolog.'
: The error occurred in C:\Inetpub\wwwroot\testmsnlive.cfm: line 16
: 14 : <cfhttp method="GET" url="">
: 15 :
: 16 : <cfset live_doc = #xmlparse(cfhttp.filecontent)#>
: 17 : <cfdump var="#live_doc#">
: 18 :

Note: for test reasons ... (see code) I've output the #livebody# to tell myself what URL string I'm trying to pass.
Shown as '#livebody# outputs as '?Appid=123456789012345678901234567890&query=&sources=news'
* where appid is not real on EE here.

If I run that livebody output in a browser ... it works.

What am I doing wrong!? any ideas?



<cfset liveappid = '123456789012345678901234567890'>
<cfset livequery = ''>
<cfset livesources = 'news'>
<cfset livemarket = ''>
<cfset liveUIlanguage='en'>
<cfset livelatitude = '47.603828'>
<cfset livelongitude = '-122.328567'>
<cfset liveradius = 250>
<cfset livenewssortoption = 'Date'>
<cfset livebody = "?Appid=" & #liveappid# & "&query=" & #livequery# & "&sources=" & #livesources#>
<cfhttp method="GET" url="">
<cfset live_doc = #xmlparse(cfhttp.filecontent)#>
<cfdump var="#live_doc#">
** note: liveappid is not my real appid (for obvious reasons)

Open in new window

Who is Participating?
_agx_Connect With a Mentor Commented:
>  <cfset livebody = "?Appid=" & #liveappid# & "&query=" & #livequery# & "&sources=" & #livesources#>
> ...
>  <cfset live_doc = #xmlparse(cfhttp.filecontent)#>

BTW,  you do not need those extra # signs. The code will still work if you leave them in, but would be cleaner without them:

<cfset livebody = "?Appid="& liveappid & "&query=" & livequery & "&sources=" & livesources>
<cfset live_doc = xmlparse(cfhttp.filecontent)>
If you are having problems, always dump the cfhttp results. Chances are the results are not what you think.  In your case the cfhttp response was probably "Connection Failure". Since that is not valid xml, xmlParse failed.

It seems to work with the addition of this tip:

<cfhttp method="GET" url="">
      <cfhttpparam type="header" name="Accept-Encoding" value="*" />
<!--- see what is returned. is it valid xml? --->
<cfdump var="#cfhttp.filecontent#">

rcbuchananAuthor Commented:
Bloody Hell!

Thanks mate!
Yes - I'm a sloppy newbie at CF but ... all this helps very much!

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

rcbuchananAuthor Commented:
Brilliant AND polite!
Eh, we are sloppy newbies at something ;-)
> Eh, we are sloppy newbies at something ;-)

   ... we are _all_ sloppy newbies at something (Obviously, I am a typing newbie today ;-)  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.