c# - Is getting post data from HttpListenerRequest asynchronously possible? -


MSDN gives us an example to get the post data.

Public static zero ShowRequestData (HttpListenerRequest request) {If (Request.HasEntityBody) {Console.WriteLine ("No customer data was sent with request."); Return; } System.IO.stream body = request.InputStream; System.Text.Encoding encoding = request.ContentEncoding; System.IO.StreamReader Reader = New System.io.StreamRedder (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.light line ("start of client data:"); // Convert the data to a string and display it on the console. String s = reader.ReadToEnd (); Console.WriteLine (s); Console.light line ("end of client data"); Body.Close (); Reader.Close (); // If you have finished with the request, then it should also be closed. }

I checked the streamreader class and did not start any ... end ... methods What does this mean that the post data is retrieved in asynchronous Can not be done? Or has it already been received before the callback of HTTPPL?

A part of the slow post data comes in, so I do not want to thread one.

What is the right asynchronous way to do this? (Or is it correctly readed?)

thanks

R

You can call your incoming stream instead of using it.


UPDATE: Here is an example of using Beginning Reed on a stream:

  class state {get public stream stream { Set; } Public byte [] Buffer {Received; Set; }} Class Program {Personal Consultation IV Size = 1024; Static Zero Main (string [] ARGs) {var stream = new filestream ("test.txt", open FlameMode, File Access. Read, FireShare, RedWrite); Var state = new state {stream = stream, buffer = new byte [chunky]}; Var ar = stream.BeginRead (state buffer, 0, state buffer, long, callback, state); While (! Ar.IsCompleted) {Thread.Sleep (10); }} Fixed zero callback (IAsyncResult AR) {var state = (state) ar.AsyncState; Var bytes read = stat. Stream And Reid (AR); If (bytes read> 0) {byte [buffer = new byte [byte reed]; Buffer BlockCopy (state buffer, 0, buffer, 0, bytes read); // Get something with the received buffer Console.Write (Encoding.UTF8.GetString (buffer)); State.stream.biggerad (state buffer, 0, state buffer, callback, state); } And {// stream reached the end of the state. Stream Dishes (); }}}  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -