Process raw HTTP request content

*爱你&永不变心* 提交于 2019-12-04 05:12:46

Something like this placed in your onload event.

if (Request.RequestType == "POST")
{
    using (StreamReader sr = new StreamReader(Request.InputStream))
    {
        if (sr.ReadLine() == "SUCCESS")
        {
            /* Do your parsing here */
        }
    }
}

Mind you that they might want some special sort of response to (ie; not your full webpage), so you might do something like this after you're done parsing.

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Thanks!");
Response.End();

Update: this should be done in a Generic Handler (.ashx) file in order to avoid a great deal of overhead from the page model. Check out this article for more information about .ashx files

Use an IHttpHandler and avoid the Page model overhead (which you don't need), but use Request.Form to get the values so you don't have to parse name value pairs yourself. Just pretend you're in PHP or Classic ASP (or ASP.NET MVC, for that matter). ;)

I'd strongly recommend saving each request to some file.

This way, you can always go back to the actual contents of it later. You can thank me later, when you find that hostile-endian, koi-8 encoded, [...], whatever it was that stumped your parser...

Well if the incoming data is in a standard form encoded POST format, then using the Request.Form array will give you all the data in a nice to handle manner.

If not then I can't see any way other than using Request.InputStream.

If I'm reading your question right, I think you're looking for the InputStream property on the Request object. Keep in mind that this is a firehose stream, so you can't reset it.

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