How to use .net 1.1 HttpWebRequest class to post the data to a secured server (https)?

Following code I am using to post data to an external server. The url is like "".
How can I post to a secured server (https) like  "" and how to test?
     public static string sendWebRequest(string URL, string Query)
                        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(URL);
                        httpRequest.Method = "POST";
                        httpRequest.ContentLength = Query.Length;
                        System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

                        httpRequest.ContentType = "application/x-www-form-urlencoded";
                        Stream httpRequestStream = httpRequest.GetRequestStream();
                        byte[] b = System.Text.Encoding.ASCII.GetBytes(Query);
                        httpRequestStream.Write(b, 0, b.Length);

                        Stream streamResponse = httpRequest.GetResponse().GetResponseStream();
                        StreamReader      streamReader = new StreamReader(streamResponse);
                        string strResponse = streamReader.ReadToEnd();
                        return strResponse;
                  catch (System.Net.WebException e)
                        throw e;
Who is Participating?

Improve company productivity with a Business Account.Sign Up

novynovConnect With a Mentor Commented: I understand more....and it isn't a stupid question. For you to use SSL on your webserver, yes you need a server certificate installed.

Assuming you are using IIS, this is a matter of generating a certificate request, getting it signed, installing the certificate, and then setting up IIS to use/require SSL in the apps/virtual directories of your choice.

Configuring IIS to do the above is fairly straightforward, though I believe there may be some slight differences in the specfic steps between IIS 6.0 and 7.0. A quick Google will give you some specific walkthroughs.

The biggest rock sometimes can be getting your certificate. A production ready certificate costs money and requires that you know the domain that you are going to be using - certs are issued on a per domain basis.

What many developers do is obtain a "self signed" certificate. There are a number of ways of doing this, including setting up your own certificate authority server, using the SelfSSL tool included in the IIS 6.0 resource kit or using tools like openssl ( A Google search of "self signed ssl" should point you at a number of options.

Once you have your test certificate installed, you may also need to install a certificate on the client machine you'll be testing on. This certificate is normally that of the signer of your server certificate (i.e. the Certificate Authority). Doing this instructs your browser to trust all certificates that have been signed by the particular CA. If you don't do this step, many browsers will complain that the server's certificate may not be trustworthy. In many cases, you can still use the website - but you'll just have to deal with the annoying browser complaints.

I hope this helps. Here are some links to some reading that may help you as you ramp up in this area:

How the SSL handshake works:
How SSL works:
Overview of public/private keys and server certs:
Creating an SSL cert request in IIS 6.0:
How SSL works from Verisign, a company that sells certs:
IIS 6.0 resource kit tools:

Let me know if I can be of more assistance.
I may be misundertanding your question or missing something, but I don't believe there is any difference. You should be able to use HttpWebRequest against an https url with no problems and no additional coding (i.e. no need to mess with certificates, etc. - it just works).

One problem I have seen mention of regarded using HttpWebRequest from within an ASP.NET application. I believe the root of the problem had to do with the account that IIS was running under - and not having access to the key store in order to authenticate the server credentials during the SSL handshake.

Have you tried just using HttpWebRequest as is? Did you run into a problem? If so, what?

I hope this helps.
rsrajendran69Author Commented:
Thank you very much for your reply, I did go thru microsoft documentation saying that HttpWebRequest will work on 'https url' without any change. I have not tried yet.

My question was, how to test https URL, just change the url from http-->https and try or is there any certificates needs to be installed on the web server to test 'https' url?. I am not really very sure how the 'https' works. Any URL can be changed to https ?
please clarrify.  Excuse me if asked stupid question.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.