Results 1 to 4 of 4

Thread: Sending WebRequest over HTTPs

  1. #1
    Join Date
    Feb 2009
    Posts
    81

    Sending WebRequest over HTTPs

    I am developing an Web-application and wanted to make it online,for that i was thinking to create a POST Https webrequest .
    Do i need to encrypt?? what all i need to encrypt? how do i do that?

    Thanks for your help...

  2. #2
    Join Date
    Mar 2008
    Posts
    232

    Re: Sending WebRequest over HTTPs

    Here's a sample method that uses the System.Net.HttpWebRequest/Response
    classes. The sample assumes your XML messages should be UTF-8 encoded.

    Code:
    public void PostXml(string url, string xml) {
    byte[] bytes = Encoding.UTF8.GetBytes(xml);
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
    request.Method = "POST";
    request.ContentLength = bytes.Length;
    request.ContentType = "text/xml";
    using (Stream requestStream = request.GetRequestStream()) {
    requestStream.Write(bytes, 0, bytes.Length);
    }
    
    // This sample only checks whether we get an "OK" HTTP status code back.
    // If you must process the XML-based response, you need to read that from
    // the response stream.
    using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
    {
    if (response.StatusCode != HttpStatusCode.OK) {
    string message = String.Format(
    "POST failed. Received HTTP {0}",
    response.StatusCode);
    throw new ApplicationException(message);
    }
    }
    }
    Cheers,

  3. #3
    Join Date
    Mar 2008
    Posts
    227

    Re: Sending WebRequest over HTTPs

    The .NET Framework provides new tools for retrieving HTTP content that are powerful and scalable in a single package. If you've ever worked in pre-.NET applications and tried to retrieve HTTP content you probably know that there are a number of different tools available: WinInet (Win32 API), XMLHTTP (part of MSXML) and recently the new WinHTTP COM library. These tools invariably all worked in some situations, but none of them really fit the bill for all instances. For example, WinInet can't scale on the server with no multi-threading support. XMLHTTP was too simple and didn't support all aspects of the HTTP model. WinHTTP which is the latest Microsoft tool for COM solves many of these problems but it doesn't work at all on Win9x, which makes it a bad choice for a client tool integrated into broad distribution apps at least for the moment until XP take a strong hold.

    The.NET framework greatly simplifies HTTP access with a pair of classes HttpWebRequest and HttpWebResponse. These classes provide just about all of the functionality provided through the HTTP protocol in a straightforward manner. The basics of returning content from the Web requires very little code (see Listing 1).

    Code:
    string lcUrl = "http://www._IDEA.com/TestPage.wwd";
    
     
    
    // *** Establish the request
    
    HttpWebRequest loHttp =
    
         (HttpWebRequest) WebRequest.Create(lcUrl);
    
     
    
    // *** Set properties
    
    loHttp.Timeout = 10000;     // 10 secs
    
    loHttp.UserAgent = "Code Sample Web Client";
    
     
    
    // *** Retrieve request info headers
    
    HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse();
    
     
    
    Encoding enc = Encoding.GetEncoding(1252);  // Windows default Code Page
    
     
    
    StreamReader loResponseStream =
    
       new StreamReader(loWebResponse.GetResponseStream(),enc);
    
     
    
    string lcHtml = loResponseStream.ReadToEnd();
    
     
    
    loWebResponse.Close();
    
    loResponseStream.Close();

  4. #4
    Join Date
    Jan 2006
    Posts
    211

    Re: Sending WebRequest over HTTPs

    The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.

    Do not use the HttpWebRequest constructor. Use the WebRequest..::.Create method to initialize new HttpWebRequest objects. If the scheme for the Uniform Resource Identifier (URI) is http:// or https://, Create returns an HttpWebRequest object.

    The GetResponse method makes a synchronous request to the resource specified in the RequestUri property and returns an HttpWebResponse that contains the response. You can make an asynchronous request to the resource using the BeginGetResponse and EndGetResponse methods.

    When you want to send data to the resource, the GetRequestStream method returns a Stream object to use to send data. The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the send data stream.

    for more detail:
    http://msdn.microsoft.com/en-us/libr...ebrequest.aspx

Similar Threads

  1. How to find HTTPS key location
    By Kewda Sho in forum Networking & Security
    Replies: 3
    Last Post: 23-11-2010, 05:45 AM
  2. Can't go to ANY HTTPS sites
    By Ajabu in forum Technology & Internet
    Replies: 4
    Last Post: 18-09-2010, 04:22 AM
  3. Configuring Http and Https with IIS
    By Santosh24 in forum Networking & Security
    Replies: 4
    Last Post: 29-01-2010, 04:42 PM
  4. Cannot browse https
    By Abhiraj in forum Technology & Internet
    Replies: 3
    Last Post: 28-07-2009, 11:08 PM
  5. To POST http WebRequest!
    By RadhaV in forum Software Development
    Replies: 2
    Last Post: 02-02-2009, 09:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,935,660.40352 seconds with 16 queries