home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / WebRequests / clientGETasync.aspx < prev    next >
Encoding:
Text File  |  2000-06-11  |  2.1 KB  |  52 lines

  1. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  2.  
  3. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  4.  
  5. <script language="C#" runat="server">
  6.  
  7.     public void Page_Load(Object sender, EventArgs E) 
  8.     {
  9.         // shell the explorer to a directory
  10.         Ref.RunSample = Server.MapPath("/quickstart/howto/samples/net/WebRequests");
  11.  
  12.         // run an aspx page directly
  13.         // Ref.RunSample = "/quickstart/howto/samples/BaseDataTypes/Sort/Sort.aspx";
  14.  
  15.         Ref.ViewSource = "/quickstart/howto/samples/net/WebRequests/clientGETasync.src";
  16.         Ref.Icon = "/quickstart/images/genicon.gif";
  17.         Ref.Caption = "ClientGETasync.exe";
  18.     }
  19.  
  20. </script>
  21.  
  22. <h4>How Do I...Make a GET request asynchronously?</h4>
  23.  
  24. <div class="indent" style="width:660">
  25. <P>
  26. This sample illustrates using the WebRequest and WebResponse classes to make a GET request on a URI asynchronously.
  27. </P>
  28. <P>
  29. This sample is similar to the other WebRequest samples, with the difference found in the <I>Begin</I> and <I>End</i> async-style function calls. Put simply, instead of calling <B>GetResponse</B> a call is made to the function <B>BeginGetResponse</B>, with the callback function sent as a parameter.
  30. </P>
  31. <P>
  32. This function <B>RespCallback</B>, takes an object of type <B>IASyncResult</B>. This object contains an object <B>AsyncObject</B> that can be cast as a <B>HttpWebRequest</B>. Calling this casted objects <B>EndGetResponse</B> method will return a WebResponse object (which is cast as an HttpWebResponse in this case.)
  33. </P>
  34. <P>
  35. From here, this example is like the others. It pulls out the response from the stream and writes it out to the console. However, this example is using the StreamReader and StreamWriter classes to do this.
  36. </p>
  37. </div>
  38.  
  39. <h4>Example</h4>
  40.  
  41. <Acme:SourceRef id="Ref" runat="server" />
  42.  
  43. <h4>Source Code</h4>
  44.  
  45. <div class="code">
  46. <xmp>
  47. <!-- #include virtual="/quickstart/howto/samples/net/WebRequests/clientGETasync.cs" -->
  48. </xmp>
  49. </div>
  50.  
  51. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->
  52.