Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   |   Class Browser
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

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

C# ClientGETasync.exe
View Source

[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\net\WebRequests\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




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


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2008  Mindcracker LLC. All Rights Reserved