Receiving XML data POSTed to an ASP.Net Page

G

Guest

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.
 
M

Martin Honnen

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?
 
G

Guest

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.
 
J

Joerg Jooss

Thus wrote (e-mail address removed),
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,
 
G

Guest

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.
 
J

Joerg Jooss

Thus wrote (e-mail address removed),
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,
 
G

Guest

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.
 
M

Martin Honnen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top