Error reading the HTTPListenerRequest InputStream

Hi Friends,

When I try to read the incoming client request data using the HttpListenerRequest.InputStream property, I'm getting the following exception (not everytime) -

System.Net.HttpListenerException: The I/O operation has been aborted because of either a thread exit or an application request

Server stack trace:
at System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at HttpListenerLibrary.HttpListenerWrapper.ProcessRequest() in C:\AcsSim\HttpListenerLibrary\HttpListenerLibrary.cs:line 901
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

The server doesn't crash after this but stops receiving any further requests. What could be the problem that makes it do so

Do I have any way of finding out what kind of request is this

Can I programmatically insert a breakpoint in the code when this exception comes

How can I ensure that if this exception happens my HttpListener still continues to receive packets

Thanks for going through my problem.

Regards,

Kunal

P.S. The code that I use to read the inputstream is as follows -

if (!request.HasEntityBody)
{
Console.WriteLine("No client data was sent with the request.");
return;
}
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = request.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);


string s = reader.ReadToEnd();
Console.WriteLine(s);
body.Close();
reader.Close();




Answer this question

Error reading the HTTPListenerRequest InputStream

  • Error reading the HTTPListenerRequest InputStream