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

左心房为你撑大大i 提交于 2019-12-07 03:07:45

问题


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 ?


回答1:


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



回答2:


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



回答3:


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);



回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/870022/how-to-dump-the-whole-post-data-to-a-file-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!