Problem getting XML through network/proxy

Hi,

I was following the "Gadget Developer's Guide" to create a simple one that gets XML from my machine and render it as HTML, The XML is exactly the htmlcontent.xml in the guide, and I tested the URL works fine, the response on GET request looks like:

HTTP/1.1 200 OK
Content-Length: 418
Content-Type: text/xml
Last-Modified: Wed, 13 Dec 2006 18:26:31 GMT
Accept-Ranges: bytes
ETag: "6e595436e41ec71:36c"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Thu, 14 Dec 2006 03:22:43 GMT
Connection: close

<?xml version="1.0" encoding="utf-8"?>
<XmlContentDoc>
<Content type="html">
<![CDATA[
<B>cduan4!</B>
]]>
</Content>
<Content type="html">
<![CDATA[
<br /><br />

Best viewed on <a href="http://www.live.com">duan5!</a></p>
]]>
</Content>
</XmlContentDoc>

Now my Gadget JS file has the following function for network request:

function HtmlDownloadComplete(response)
{
if (response.status == 200)
{
if (response.responseXML)
{

var htmlNodes = response.responseXML.selectNodes("XmlContentDoc/Content[@type='html']");
for (var i = 0; i < htmlNodes.length; i++)
{
// Pull the html out of the XML document and stuff it into our containing html element
p_elSource.innerHTML += htmlNodes[ i ].text;
}
}
}
}

// Queue a download of the XML that contains our html fragments
// You should replace the path below to the path to your XML file
var req = Web.Network.createRequest(
Web.Network.Type.XML,
// "http://<myhost.dns.name>/Gadgets/chengd/test.html",
// [updated with correct info]
"http://<myhost.dns.name>/Gadgets/chengd/htmlcontent.xml",
{proxy:"generic", numItems:5},
HtmlDownloadComplete);

req.execute();

But when it runs, the returned response.responseXML has not child element. I also used fidller to track the request to proxy, and the response is:

HTTP/1.1 200 OK
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Content-Length: 0
Via: 1.1 RED-PRXY-30
Date: Thu, 14 Dec 2006 04:13:05 GMT
Server: Microsoft-IIS/6.0
P3P: CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo"
X-Powered-By: ASP.NET
S: WEBA08
X-AspNet-Version: 2.0.50727
Cache-Control: private

I tried many time and it just won't get back the XML content. Any help is highly appreciated!

Chenggang

[2978 byte] By [duancg] at [2008-1-13]
# 1

Your createRequest() call doesn't look right. The URL you listed above is "http://<myhost.dns.name>/Gadgets/chengd/test.html", which is not an XML file. Your web server is going to serve that up as text/plain, not text/xml. If you saved your XML file on the server as "test.html", try renaming it to "test.xml" and adjust your createRequest() call appropriately.

The createRequest() proxy will only do XML data, and is very finicky about MIME types (needs to be text/xml or application/xml for XML data). This is something to keep in mind if you're doing server-side programming, since most server-side languages will default to text/plain unless you force the content header to text/xml or application/xml. For static files, web servers figure out what to return based on the file type, which in your case is .html (text/plain), not .xml (text/xml).

ToddOs at 2007-9-3 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 2
Sorry, my typo. I updated the orginal thread with correct URL that I tried. Any idea for help? Thank!
duancg at 2007-9-3 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 3

Found the problem, the proxy doesn't seem to be able to reach the URL that I specified. When I change the URL to some public RSS/XML, it works.

BTW, for those HTTP experts, it is normal that in this case the proxy returns 200/OK? Just curious.

duancg at 2007-9-3 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 4

The proxy can behave oddly in cases where it can't reach the host it's trying to hit, but I'll leave that to the live.com guys since it's likely a bug. I don't know how the live.com proxy works, but my assumption is that it's a special piece of software and not just a squid or ISA proxy setup (evidenced by its inability to work with non-XML sources, for example).

If you're doing localhost development, you need to bypass the proxy (obviously the live.com servers can't hit your localhost, because localhost to them is different). If you had the XML file on another machine on your internal network, that won't work either (proxy get there either). This, among many other reasons, is why I generally don't do localhost-based development. Web hosting can be had for very cheap or even free, so why not use it? The benefits (ability to test your code with the proxies, use the RSS proxy, no monkeying around with browser security settings, the ability to test with Firefox and Opera as well as IE, possibility of running a "beta" of your gadget before publishing to Gallery, etc) of "live" development outweight the negatives (you're working on code "out in the wild"). You probably have free web space from your ISP, and even a Geocities account will be enough for development and testing purposes. If you want or need to do more (building dynamic data sources using server-side scripting and database access, for example), get yourself a $5-10/mo hosting plan with one of the many web hosting companies out there. Plans exist from the most basic FTP interface to full-blown SSH or Terminal Server access, depending on the hoster you choose and how much you're willing to spend.

(BTW, I'm not shilling for any particular hosting company. I'll happily refer you to the hoster I use if you like, but I'm explicitly not posting it to avoid looking like an advertisement :).

ToddOs at 2007-9-3 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 5
Thanks! That is very helpful! I totally agree with you that the 'live' development is much better. In my case, I do need the server side scripting, so the best is to save money to buy a plan :)
duancg at 2007-9-3 > top of Msdn Tech,Gadgets,Web Gadget Development...