Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dump the whole POST data to a file in ASP.NET

I'm currently trying to port an app from asp.net to php, however I just hit a wall and need a hand with this.

I need to dump all the data an .aspx recieves via POST to a file, but I have no clue on how to do this

any ideas ?

like image 359
perrohunter Avatar asked May 15 '09 17:05

perrohunter


2 Answers

You can use the InputStream property of the Request object. This will give you the raw data of the http request. Generally you might want to do this as a custom http handler, but I believe you can do it any time.

if (Request.RequestType == "POST")
{
    using (StreamReader reader = new StreamReader(Request.InputStream))
    {
        // read the stream here using reader.ReadLine() and do your stuff.
    }
}
like image 181
womp Avatar answered Oct 11 '22 13:10

womp


If you just want POST data, then you can use Request.Form.ToString() to get all the data in a url encoded manner.

if (Request.RequestType == "POST") {
    string myData = Request.Form.ToString();
    writeData(myData); //use the string to dump it into a file,
}
like image 26
Waqas Hussain Avatar answered Oct 11 '22 13:10

Waqas Hussain