Matt Facer Matt Facer - 2 years ago 179
ASP.NET (C#) Question

using Request.GetBufferlessInputStream() correctly for POST data c#

I have created a c# web page which will be listening for POST data from a service. I've seen that I may need to use Request.GetBufferlessInputStream() which will read in the page data. I will then process this data further in my code.

However, I cannot get the post data! I have found that I need to use

Stream httpStream = Request.GetBufferlessInputStream();

but I am not sure how to then read that. I have tried reading from 0 to the end, but get only numbers returned (assume byte data?).

I basically want to see a string! I've been using CURL to fake a post. That code is here

curl -H "Content Type: application/xml" -d "<callback var=\"matt\">" -X POST http://localhost:1111/Default.aspx

So I would expect my script to output
<callback var="matt">
. Any ideas?

Answer Source

This is what you need-

Stream stream = Request.InputStream;

StreamReader reader = new StreamReader(stream, Request.ContentEncoding);

string text = reader.ReadToEnd();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download