Cómo llamar a HttpWebRequest de forma asincrónica
¿Cómo llamar a HttpWebRequest de forma asíncrona?
public static ManualResetEvent allDone = new ManualResetEvent(false);
static void Main(string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("/example.aspx");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.BeginGetRequestStream(new AsyncCallback(ReadCallback), solicitud);
allDone.WaitOne();
Respuesta HttpWebResponse = (HttpWebResponse )request.GetResponse();
Stream streamResponse = respuesta.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
cadena respuestaString = streamRead .ReadToEnd();
streamResponse.Close();
streamRead.Close();
respuesta.Close();
Console.WriteLine(responseString);
Console.ReadKey();