Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Make a GET request asynchronously?

This sample illustrates how to use the WebRequest and WebResponse classes to make a GET request on a URI asynchronously.

This sample is similar to the other WebRequest samples, with the difference found in the Begin and End async-style function calls. Put simply, instead of calling GetResponse, a call is made to the function BeginGetResponse, with the callback function and a state object specified as parameters.

This function RespCallback, takes an object of type IASyncResult. This object contains an object AsyncState that is the same state object passed to the call toBeginGetResponse. The state object is casted to a custom type RequestState that can be used to get a handle to the original HttpWebRequest. Calling the original request's EndGetResponse method will return a WebResponse object (which is cast as an HttpWebResponse in this case.) Finally, the response is read asynchronously from the response by getting the value of the ResponseStream property on the response object.

From here, this example is like the others. It pulls out the response from the stream and writes it out to the console.

Example

VB ClientGETasync.exe
View Source
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\howto\samples\net\WebRequests\]



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.