How to dump all POST data to a file in ASP.NET

I'm currently trying to port an application from asp.net to php, but I just hit the wall and need a hand with that.

I need to dump all the data that ASPX receives through POST to a file, but I do not know how to do it

any ideas?

+6
request postdata
source share
5 answers

You can use the InputStream property of the Request object. This will give you raw HTTP request data. You can usually do this as a custom http handler, but I believe you can do this anytime.

if (Request.RequestType == "POST") { using (StreamReader reader = new StreamReader(Request.InputStream)) { // read the stream here using reader.ReadLine() and do your stuff. } } 
+8
source share

You can use BinaryRead to read from the request body:

 Request.BinaryRead 

Or you can get a link to the Stream object with:

 Request.InputStream 

Then you can use CopyStream :

 using (FileStream fs = new FileStream(...)) CopyStream(fs, Request.InputStream); 
+6
source share

If you just need POST data, you can use Request.Form.ToString () to get all url encoded data.

 if (Request.RequestType == "POST") { string myData = Request.Form.ToString(); writeData(myData); //use the string to dump it into a file, } 
+5
source share

You can use a proxy application such as Fiddler . This will allow you to view all the data that has been transferred, and also save them to a file as needed.

+2
source share

The best way to do this is through some browser plugin like Fiddler or LiveHttpHeaders (Firefox only). Then you can intercept the raw POST data.

0
source share

All Articles