How to send HTTPS-Post request using C# application


A

Arti

Hi,

I am trying to access a servlet hosted on Tomcat server using HTTPS
Post protocol. I am getting the exception:
"The underlying connection was closed: Could not establish trust
relationship with remote server".

Below is the code snippet. The same worked fine for HTTP POST. Then
when I configured the Tomcat server ffor HTTPS, and modified the code
by just changing the protocol from http to https. What more is to be
done for HTTPS??
I am not sure where is the gap.

Any help/url is highly appreciated.

------------------------------------------------------------------------------------------------------------------------
string str = "TEST DATA";
string uri =
"https://127.0.0.1:8443/MYLOGINPAGE/AMCWEBLOGINGATEWAY?LOGINID=guest&PASSWD=passwd12";
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri);request.KeepAlive = false;
request.ProtocolVersion=HttpVersion.Version10;
request.Method = "POST";

byte[] postBytes = Encoding.ASCII.GetBytes(str);
request.ContentType = "text";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();

HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Console.WriteLine(new
StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine("Headers:");
Console.WriteLine(response.Headers.ToString());

------------------------------------------------------------------------------------------------------------------------
 
Ad

Advertisements

Ad

Advertisements

A

Arti

Hi,

In my case the servlet is hosted on APACHE TOMCAT server. So how do I
go about it.

Thanks,
Arti
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top