home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / WebRequests / clientGETwithProxy.aspx < prev    next >
Encoding:
Text File  |  2000-06-11  |  2.8 KB  |  56 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/clientGETwithProxy.src";
  16.         Ref.Icon = "/quickstart/images/genicon.gif";
  17.         Ref.Caption = "ClientGETwithProxy.exe";
  18.     }
  19.  
  20. </script>
  21.  
  22. <h4>How Do I...Make a GET request through a proxy?</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 through a proxy.
  27. </P>
  28. <P>
  29. This sample is very similar to the clientGET.cs sample. The difference is in the creation and attachment of the proxy object. A <B>DefaultControlObject</B> is created and (in the constructor) set to the name and port of the proxy server. This objects <B>ProxyNoLocal</B> property to true, which means to bypass the proxy for local LAN servers. The final step is to set this proxy as the global proxy for all requests with the line <B>GlobalProxySelection.Select = proxyObject;</B>.
  30. </P><P>
  31. The function getPage is where the specific details of making the request can be found. The rest of the code in this sample is for taking command-line parameters, and displaying help usage for the parameters as well. This sample program is a command-line utility that runs at the command prompt.
  32. </P><P>
  33. The <B>getPage</B> function takes a string parameter, which is the URL (or URI) of the web page to request. This URI is then included as a parameter in a call to <B>WebRequestFactory.Create</B> which creates a <B>WebRequest</B> object.
  34. </P>
  35. <P>
  36. The <B>GetResponse</B> function of the WebRequest object is then used to get a <B>WebResponse</B> object. This object can be used to get the status code of the response, as well as the actual response stream, for instance a web page. 
  37. </P>
  38. <P>
  39. Actually writing out the stream can take several different forms. This example reads a byte array (of 512 bytes) into the Byte[] variable <B>read</B> with the <B>Read</B> function. It then writes out the 512 bytes with a Console.WriteLine function: Console.Write(System.Text.Encoding.ASCII.GetString(read, 0, bytes));
  40. </P>
  41. </div>
  42.  
  43. <h4>Example</h4>
  44.  
  45. <Acme:SourceRef id="Ref" runat="server" />
  46.  
  47. <h4>Source Code</h4>
  48.  
  49. <div class="code">
  50. <xmp>
  51. <!-- #include virtual="/quickstart/howto/samples/net/WebRequests/clientGETwithProxy.cs" -->
  52. </xmp>
  53. </div>
  54.  
  55. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->
  56.