home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / WebRequests / clientGETwithNTLM.aspx < prev    next >
Encoding:
Text File  |  2000-06-11  |  2.8 KB  |  59 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/clientGETwithNTLM.src";
  16.         Ref.Icon = "/quickstart/images/genicon.gif";
  17.         Ref.Caption = "ClientGETwithNTLM.exe";
  18.     }
  19.  
  20. </script>
  21.  
  22. <h4>How Do I...Make a GET request with NTLM?</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 with NTLM authentication.
  27. </P>
  28. <P>
  29. This sample is very similar to the clientGET.cs sample. The difference is in the addition of the SingleCredentials object to handle setting a username, password, and domain to allow for NTLM authentication. Other authentication types are also just as easy. A <B>SingleCredentials</B> object is created with a username, password, and domain sent in the constructor. The object is then attached to the <B>WebRequest</B> object's <B>Credentials</B> property. And that is it!
  30. </P>
  31. <P>
  32. 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.
  33. </P>
  34. <P>
  35. 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.
  36. </P>
  37. <P>
  38. 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. 
  39. </P>
  40. <P>
  41. 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));
  42. </p>
  43.  
  44. </div>
  45.  
  46. <h4>Example</h4>
  47.  
  48. <Acme:SourceRef id="Ref" runat="server" />
  49.  
  50. <h4>Source Code</h4>
  51.  
  52. <div class="code">
  53. <xmp>
  54. <!-- #include virtual="/quickstart/howto/samples/net/WebRequests/clientGETwithNTLM.cs" -->
  55. </xmp>
  56. </div>
  57.  
  58. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->
  59.