Help reading JSON from HttpContext.InputStream

前端 未结 2 1590
挽巷
挽巷 2020-12-04 02:07

I have created a HttpModule to capture requests for auditing purposes.

For Ajax requests to a web method I would like to also log the JSON data associated with the r

相关标签:
2条回答
  • 2020-12-04 03:00

    I needed to reset the position of the stream before reading...

    request.InputStream.Position = 0;
    using (StreamReader inputStream = new StreamReader(request.InputStream))
    {
    return inputStream.ReadToEnd();
    }

    0 讨论(0)
  • 2020-12-04 03:04

    The stream can't be read as far as i know. You might write you own handler, then buffer the stream, by reading and writing to another stream.

    To parse the JSON part you might try

    System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject(string input);
    
    0 讨论(0)
提交回复
热议问题