0

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();
Response.Write(httpStream.ToString());

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?

2 Answers 2

2

This is what you need-

Stream stream = Request.InputStream;

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

string text = reader.ReadToEnd();
Sign up to request clarification or add additional context in comments.

Comments

0
using (var streamReader = new StreamReader(Request.GetBufferlessInputStream(), Request.ContentEncoding))
{
    string requestBody = await streamReader.ReadToEndAsync();
}

This reads using the non-blocking async method and the using statement properly disposes the stream.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.