471,066 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

How to send HTTPS-Post request using C# application

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()).ReadToE nd());
Console.WriteLine("Headers:");
Console.WriteLine(response.Headers.ToString());

------------------------------------------------------------------------------------------------------------------------

Nov 11 '06 #1
2 26394
This article could help: http://support.microsoft.com/kb/823177/en-us

"Arti" <ar********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
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()).ReadToE nd());
Console.WriteLine("Headers:");
Console.WriteLine(response.Headers.ToString());

------------------------------------------------------------------------------------------------------------------------

Nov 12 '06 #2
Hi,

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

Thanks,
Arti

Nov 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Google Mike | last post: by
1 post views Thread by Josip Krapac | last post: by
1 post views Thread by Hasan D | last post: by
1 post views Thread by Kenneth Keeley | last post: by
3 posts views Thread by zn | last post: by
reply views Thread by Dima | last post: by
reply views Thread by marcello lussana | last post: by
6 posts views Thread by aRTx | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.