By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Receiving XML data POSTed to an ASP.Net Page

P: n/a
I have an piece of software that is sending an HTTP POST request to an
ASP.Net page. The data posted consists of a chunk of XML data.

For some reason (Based on my net research, and my tests at least) .Net
does not like getting XML data as HTTP POST. If I call
Request.SaveAs(...) to save a copy of the request to examine, it
doesn't match the request sent (verified my monitoring network
traffic). I suspect some filtering is occurring somewhere in the
framework before I get to process it.

Can anyone:

a) Confirm this?
b) Suggest a way around it.
I'm well aware I could just post the data to a web service, and that is
how it is currently being achieved. However, thats not how I want it to
be done.

Andy.

Mar 10 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a


no****@starsphere.net wrote:
I have an piece of software that is sending an HTTP POST request to an
ASP.Net page. The data posted consists of a chunk of XML data.


I don't know of any problems in accessing e.g.
Request.InputStream
and use that with an XmlTextReader or XPathDocument or XmlDocument to
process the XML if well-formed XML has been posted.

That assumes that the client posts the XML as the body of the HTTP
request with Content-Type application/xml or text/xml for instance.

What exactly do you want to do with the received XML, what exactly does
not work?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 10 '06 #2

P: n/a
I want to do, exactly what you have just written.

The problem is the InputStream is completely empty. The application
posting the data isn't setting the content type to xml though (I sadly
have no control over that). That may be why the content doesn't appear?

Posting the same data to a traditional ASP page gives the expected
result.

Andy.

Mar 11 '06 #3

P: n/a
Thus wrote no****@starsphere.net,
I want to do, exactly what you have just written.

The problem is the InputStream is completely empty. The application
posting the data isn't setting the content type to xml though (I sadly
have no control over that). That may be why the content doesn't
appear?


No, ASP.NET doesn't care about content types other than form data. Can you
run a test with Fiddler and capture the traffic?

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 11 '06 #4

P: n/a
> No, ASP.NET doesn't care about content types other than form data. Can you
run a test with Fiddler and capture the traffic?


Sure. I was using ettercap before, but Fiddler seems a more friendly
way of doing it.

The request made to the ASP.Net page is shown below.

POST /Flash/xml_db.aspx?Mode=Post HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 1776
Accept-Encoding: gzip, deflate
Host: dairy
Proxy-Connection: Keep-Alive
Pragma: no-cache
Cookie: ASP.NET_SessionId=cn3lg42e0ub5dpvhp2zhrk55

<doc><data> ... [Actual content here removed to keep this short] ...
</data></doc>
As you can see, the application making the request is claiming it is
"form-urlencoded" when that clearly is not the case. If I do another
test posting EXACTLY the same request but setting content-type to
"text/xml", everything works as intended. The conclusion I draw is that
..Net is seeing that the data is not the content it claims to be, and
getting rid of it?

Andy.

Mar 11 '06 #5

P: n/a
Thus wrote no****@starsphere.net,
No, ASP.NET doesn't care about content types other than form data.
Can you run a test with Fiddler and capture the traffic?

Sure. I was using ettercap before, but Fiddler seems a more friendly
way of doing it.

The request made to the ASP.Net page is shown below.

POST /Flash/xml_db.aspx?Mode=Post HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 1776
Accept-Encoding: gzip, deflate
Host: dairy
Proxy-Connection: Keep-Alive
Pragma: no-cache
Cookie: ASP.NET_SessionId=cn3lg42e0ub5dpvhp2zhrk55
<doc><data> ... [Actual content here removed to keep this short] ...
</data></doc>

As you can see, the application making the request is claiming it is
"form-urlencoded" when that clearly is not the case. If I do another
test posting EXACTLY the same request but setting content-type to
"text/xml", everything works as intended. The conclusion I draw is
that .Net is seeing that the data is not the content it claims to be,
and getting rid of it?


Yes, that's pretty much it.

Sorry, but now I'm confused -- is your problem that the client sends the
wrong content type (raw XML as form data), or is the problem solved now?

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 11 '06 #6

P: n/a
The problem is the remote client (which I have no control over) sends
the request with (what I now know is) the wrong content type to the
page (the bit I can control). ASP.Net seems to remove the content from
the request, hence Request.InputStream being empty.

So it boils down to if there is a way around this to get at the data
that has bee posted.

Mar 11 '06 #7

P: n/a


no****@starsphere.net wrote:

The request made to the ASP.Net page is shown below.

POST /Flash/xml_db.aspx?Mode=Post HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 1776
Accept-Encoding: gzip, deflate
Host: dairy
Proxy-Connection: Keep-Alive
Pragma: no-cache
Cookie: ASP.NET_SessionId=cn3lg42e0ub5dpvhp2zhrk55

<doc><data> ... [Actual content here removed to keep this short] ...
</data></doc>
As you can see, the application making the request is claiming it is
"form-urlencoded" when that clearly is not the case. If I do another
test posting EXACTLY the same request but setting content-type to
"text/xml", everything works as intended. The conclusion I draw is that
.Net is seeing that the data is not the content it claims to be, and
getting rid of it?


I have tried such a request with ASP.NET 1.1 and it then throws a server
error that validating the Request data failed.
If I add the directive
<%@ Page Language="C#" ValidateRequest="false" %>
to prevent the ASP.NET runtime from trying to validate the posted data
then I am able to use e.g.
XmlDocument requestXML = new XmlDocument();
requestXML.Load(Request.InputStream);
without problems, even if the HTTP request Content-Type is
application/x-www-form-urlencoded.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 11 '06 #8

P: n/a
That's great, thanks for your help Martin.

Mar 13 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.