Link to home
Start Free TrialLog in
Avatar of rsrajendran69
rsrajendran69

asked on

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 "http://www.microsoft.com".
How can I post to a secured server (https) like  "https://www.microsoft.com" and how to test?
       
     public static string sendWebRequest(string URL, string Query)
            {
                  try
                  {
                        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);
                        httpRequestStream.Close();

                        Stream streamResponse = httpRequest.GetResponse().GetResponseStream();
                 
                        StreamReader      streamReader = new StreamReader(streamResponse);
                        string strResponse = streamReader.ReadToEnd();
                        streamReader.Close();
                        return strResponse;
                  }
                  catch (System.Net.WebException e)
                  {
                        throw e;
                  }
            }
Avatar of novynov
novynov
Flag of United States of America image

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.
Avatar of rsrajendran69
rsrajendran69

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of novynov
novynov
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial