0
msdn給我們這個例子來檢索發佈數據。是否可以異步獲取HttpListenerRequest的發佈數據?
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.
}
我檢查StreamReader類和有沒有開始... ...結束方法。這是否意味着Post數據不能異步檢索?或者在HttpListener的回調來之前它已經被檢索到了?
我不希望獲得一個線程失速而慢後一個數據塊的用武之地。
什麼是正確的異步方式做到這一點? (或者實際上是在ReadToEnd的正確嗎?)
感謝
[R
太棒了!謝謝...! – Toad 2009-10-17 14:38:02