Solved

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

Posted on 2009-05-07
6
1,308 Views
Last Modified: 2013-12-20
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.'
:
: http://api.search.live.net/xml.aspx?Appid=123456789012345678901234567890&query=&sources=news
:  
: The error occurred in C:\Inetpub\wwwroot\testmsnlive.cfm: line 16
: 14 : <cfhttp method="GET" url="http://api.search.live.net/xml.aspx#livebody#">
: 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?

Richard


SUPPORTING INFORMATION : Live.Net FAQ Sheet for API
http://search.live.com/developers/s/API%20Basics.pdf


<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#>

<cfoutput>#livebody#</cfoutput>

 

<cfhttp method="GET" url="http://api.search.live.net/xml.aspx#livebody#">

 

<cfset live_doc = #xmlparse(cfhttp.filecontent)#>

<cfdump var="#live_doc#">

 

 

** note: liveappid is not my real appid (for obvious reasons)

Open in new window

0
Comment
Question by:rcbuchanan
  • 4
  • 2
6 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 24327248
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:
http://blog.pengoworks.com/index.cfm/2006/3/13/CFHTTP-Connection-Failures-issues-with-Gzip

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


0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 24327264
>  <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)>
0
 

Author Comment

by:rcbuchanan
ID: 24327755
Bloody Hell!
Brilliant.

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

R
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Closing Comment

by:rcbuchanan
ID: 31579047
Brilliant AND polite!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24328358
Eh, we are sloppy newbies at something ;-)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24328365
> Eh, we are sloppy newbies at something ;-)

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change time in cron 4 65
Widget to get customer remakrs in our website. 3 42
stop navigation from wrapping 7 47
What .NET URL re-routing tool did I use? 2 31
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now