Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 19-03-2009
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...
Reply With Quote
Old 19-03-2009
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.

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}",
throw new ApplicationException(message);
Reply With Quote
Old 19-03-2009
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).

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();



Reply With Quote
Old 19-03-2009
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:
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Sending WebRequest over HTTPs"
Thread Thread Starter Forum Replies Last Post
How to find HTTPS key location Kewda Sho Networking & Security 3 23-11-2010 05:45 AM
Can't go to ANY HTTPS sites Ajabu Technology & Internet 4 18-09-2010 04:22 AM
Configuring Http and Https with IIS Santosh24 Networking & Security 4 29-01-2010 04:42 PM
Cannot browse https Abhiraj Technology & Internet 3 28-07-2009 11:08 PM
To POST http WebRequest! RadhaV Software Development 2 02-02-2009 09:38 PM

All times are GMT +5.5. The time now is 03:02 AM.