题
目前,我正在尝试口的应用程序asp.net php,但是我只是撞墙和需要方面与此有关。
我需要转储的所有数据。aspx获通过后文件,但我不知道如何做到这一点
任何想法?
解决方案
可以使用请求对象的InputStream的属性。这会给你的HTTP请求的原始数据。一般来说,你可能要做到这一点作为一个自定义HTTP处理程序,但我相信你可以做到任何时候。
if (Request.RequestType == "POST")
{
using (StreamReader reader = new StreamReader(Request.InputStream))
{
// read the stream here using reader.ReadLine() and do your stuff.
}
}
其他提示
如果你只是想POST数据,那么你可以使用Request.Form.ToString()来获得在URL编码方式的所有数据。
if (Request.RequestType == "POST") {
string myData = Request.Form.ToString();
writeData(myData); //use the string to dump it into a file,
}
你可以使用 BinaryRead
读请求的身体:
Request.BinaryRead
或者你可以得到一个参考输入 Stream
对象:
Request.InputStream
然后你可以用 CopyStream
:
using (FileStream fs = new FileStream(...))
CopyStream(fs, Request.InputStream);
您可以使用代理应用例如提琴手。这将让你看到所有被传输的数据,以及将其保存到需要的文件。
最好的方式来做到这一点是通过一些browser plugin喜欢 提琴手 或 LiveHttpHeaders (Firefox)。然后你可以拦截原岗位的数据。
不隶属于 StackOverflow