home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <%
- runsample = Server.MapPath("/quickstart/howto/samples/net/WebRequests")
- viewsource = "/quickstart/howto/samples/net/WebRequests/clientGET.src"
- icon = "/quickstart/images/genicon.gif"
- caption = "ClientGET.exe"
- %>
-
- </script>
-
- <h4>How Do I...Make a GET request?</h4>
-
- <div class="indent" style="width:660">
- This sample illustrates using the WebRequest and WebResponse classes to make a GET request on a URI.
- <BR>
- <P>
- 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.
- </p>
- <P>
- 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.
- </P>
- <P>
- 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.
- </P>
- <P>
- 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));
- </p>
- </div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="<%=runsample%>">
- <img style="border-color:black" border=1 src="<%=icon%>"><br>
- </a>
- <div class="caption"><%=caption%></div><br>
- [<a target="_blank" href="<%=runsample%>">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=<%=viewsource%>">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/net/WebRequests/clientGET.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->
-