是否可以异步获取HttpListenerRequest的发布数据?

时间:2009-10-17 14:25:23

标签: c# .net http post asynchronous

msdn给我们这个例子来检索帖子数据。

 public static void ShowRequestData (HttpListenerRequest request)
 {
     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);
     if (request.ContentType != null)
     {
         Console.WriteLine("Client data content type {0}", request.ContentType);
     }
     Console.WriteLine("Client data content length {0}", request.ContentLength64);

     Console.WriteLine("Start of client data:");
     // Convert the data to a string and display it on the console.
     string s = reader.ReadToEnd();
     Console.WriteLine(s);
     Console.WriteLine("End of client data:");
     body.Close();
     reader.Close();
     // If you are finished with the request, it should be closed also.
 }

source

我检查了Streamreader类,没有Begin ... End ...方法。这是否意味着无法异步检索Post数据?或者在从HttpListener回调之前已经检索过它?

当一大堆慢速发布数据进入时,我不想得到一个线程停止。

执行此操作的正确异步方法是什么? (或者ReadToEnd实际上是否正确?)

感谢

R

0 个答案:

没有答案