I am trying to save the request and response to a file using HttpModule.
Can someone please tell me if it is possible to capture the Reponse stream and save it to a file??. I can save the request using BeginRequest.
Response.OutputStream can not be read directly (it can only be written to).
One possible solution not tested but can be tried:
1) Create a class derived from BufferedStream that overrides the Write method to do base.Write() AND write to a file (let's say the new class will be named FileWriterBufferedStream)
2) Set the HttpResponse.Filter (http://msdn.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx) to:
Response.Filter = new FileWriterBufferedStream(Response.Filter);
Thanks Aleris your responce really helped me move forward and could save the response at HttpModule level by overriding the write() method. But for somereason when it comes to the client it says :
"client found response content type of "", but expected "text/xml".request failed with empty response"
Well my mistake i figured out the cause of the exception. when i wrote the response to a file using the override write(). I need to make sure that i write the responsestream back else it returns empty stream to the client.
rcitigori
Member
2 Points
12 Posts
Http Module Save Response
Jun 11, 2008 06:36 PM|LINK
Hello Experts,
I am trying to save the request and response to a file using HttpModule. Can someone please tell me if it is possible to capture the Reponse stream and save it to a file??. I can save the request using BeginRequest.
Aleris
Member
194 Points
27 Posts
Re: Http Module Save Response
Jun 11, 2008 07:24 PM|LINK
Response.OutputStream can not be read directly (it can only be written to).
One possible solution not tested but can be tried:
1) Create a class derived from BufferedStream that overrides the Write method to do base.Write() AND write to a file (let's say the new class will be named FileWriterBufferedStream)
2) Set the HttpResponse.Filter (http://msdn.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx) to:
rcitigori
Member
2 Points
12 Posts
Re: Http Module Save Response
Jun 11, 2008 08:32 PM|LINK
Thanks Aleris your responce really helped me move forward and could save the response at HttpModule level by overriding the write() method. But for somereason when it comes to the client it says :
"client found response content type of "", but expected "text/xml".request failed with empty response"
Any ideas on the above exception:
rcitigori
Member
2 Points
12 Posts
Re: Http Module Save Response
Jun 11, 2008 09:13 PM|LINK
Well my mistake i figured out the cause of the exception. when i wrote the response to a file using the override write(). I need to make sure that i write the responsestream back else it returns empty stream to the client.
Thanks for the response.
Nafe Jeries
Member
6 Points
6 Posts
Re: Http Module Save Response
Aug 23, 2011 02:10 PM|LINK
Hellp Aleris, can you post the code, cause i'm facing this problem.
thank you