6

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 ?

5 Answers 5

8

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

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,
}
6

You can use BinaryRead to read from request body:

Request.BinaryRead

Or you could get a reference to input Stream object with:

Request.InputStream

Then you could use CopyStream:

using (FileStream fs = new FileStream(...))
    CopyStream(fs, Request.InputStream);
1
  • 3
    .NET 4.0 now has a Stream.CopyTo() method.
    – spoulson
    May 4, 2010 at 12:17
2

You could use a proxy application such as Fiddler. This will let you look at all of the data that was transferred, as well as save it to a file as needed.

1
  • perfect, this shows all of the information sent and received!
    – Dediqated
    Apr 4, 2013 at 11:59
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.