Main Page | Report this Page
.NET DotNet Forum Index  »  Visual C# Forum  »  XmlDocument.Load() Protocol...
Page 1 of 1    

XmlDocument.Load() Protocol...

Author Message
Jonathan Wood...
Posted: Fri Nov 06, 2009 10:54 pm
Guest
I'm using XmlDocument.Load to retrieve a PAD (XML) file. My code looks
something like this:

XmlDocument xml = new XmlDocument();

// Non-HTTP prefix not supported
if (!url.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
throw new Exception("PAD URL contains an unsupported protocol
prefix");

// Load XmlDocument
xml.Load(url);

When url is set to "http://www.mobiletutor.org/guitar/jar.xml", I get the
following error:

The remote server returned an error: (400) Bad Request.

I notified this site about the error and here is their response:

"FYI, this is failing because your file fetcher is not sending HTTP
Accept headers and is thus considered insecure by our Web server. You
may want to fix that..."

I don't fully understand this response but, sure enough, if I load the URL
above using Internet Explorer, it appears to work just fine.

Does XmlDocument have some protocol problems, or is there something I can do
to make my code work in this case?

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
 
Peter Duniho...
Posted: Fri Nov 06, 2009 11:49 pm
Guest
Jonathan Wood wrote:
Quote:
[...]
I notified this site about the error and here is their response:

"FYI, this is failing because your file fetcher is not sending HTTP
Accept headers and is thus considered insecure by our Web server. You
may want to fix that..."

I don't fully understand this response but, sure enough, if I load the
URL above using Internet Explorer, it appears to work just fine.

Does XmlDocument have some protocol problems, or is there something I
can do to make my code work in this case?

I'm not clear on why not including an Accept header is a security
problem, but that's probably just lack of knowledge on my part (though a
quick Google didn't turn up anything).

The way the response describes it, "Accept headers" plural, suggests
maybe it's not the Accept header per se, but one of the variants (e.g.
Accept-Charset, Accept-Encoding, etc....and not that that assumption
makes the insecurity potential any more obvious to me Sad ) that they
consider important. You may want to ask them to clarify, so that you
know _exactly_ what header you need to include and what the value for
the header should be.

As for dealing with the requirement, AFAIK there's nothing in
XmlDocument you can use to force the header to be included when calling
Load() with a URL. But, you can use the WebRequest class to resolve
your URL, and for HttpWebRequest instances, include the necessary header
(if it's not by default...I don't recall which headers are and it's not
entirely clear exactly what header is needed).

With the WebRequest instance in hand, you then just get the response,
and from that, the response stream. You can then pass the Stream
instance to the XmlDocument.Load() method instead.

Pete
 
Tim Williams...
Posted: Sat Nov 07, 2009 4:12 pm
Guest
If you follow Peter's suggestion and you need to determine which headers to
add, you can use Fiddler to monitor the headers sent by your browser
(assuming that is able to successfully fetch the file).

http://www.fiddler2.com/fiddler2/ (this is a must have tool if you're
doing anything web-related)

Tim

"Jonathan Wood" <jwood at (no spam) softcircuits.com> wrote in message
news:etOJR41XKHA.3600 at (no spam) TK2MSFTNGP04.phx.gbl...
Quote:
I'm using XmlDocument.Load to retrieve a PAD (XML) file. My code looks
something like this:

XmlDocument xml = new XmlDocument();

// Non-HTTP prefix not supported
if (!url.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
throw new Exception("PAD URL contains an unsupported protocol
prefix");

// Load XmlDocument
xml.Load(url);

When url is set to "http://www.mobiletutor.org/guitar/jar.xml", I get the
following error:

The remote server returned an error: (400) Bad Request.

I notified this site about the error and here is their response:

"FYI, this is failing because your file fetcher is not sending HTTP
Accept headers and is thus considered insecure by our Web server. You
may want to fix that..."

I don't fully understand this response but, sure enough, if I load the URL
above using Internet Explorer, it appears to work just fine.

Does XmlDocument have some protocol problems, or is there something I can
do to make my code work in this case?

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sun Dec 06, 2009 12:30 pm