473,287 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 27054
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
1
by: Josip Krapac | last post by:
Hello, I've got this situation: Servlet accessed by https (ie. https://host.domain/SecureServlet) starts a session (HttpSession session = req.getSession(true)), sets some session attributes...
1
by: Hasan D | last post by:
I'm new on this httplib and urllib. Actually I dont know what should i use. I want to fill the form in a "https" page , and return the result . I write a test code but always gives errors. I cant...
1
by: Kenneth Keeley | last post by:
Hi I wish to have a web site that has most of the pages as normal HTTP pages but has some areas that use HTTPS. I want to have it that if a user selects a link to a HTTPS page that they go there...
3
by: zn | last post by:
This is a beginner question. I need to create a page that is encrypted by SSL. The web server is already serving SSL encrypted web pages with "https" before the link. Do I need to do anything other...
0
by: Dima | last post by:
This is the beginner question. I installed j2ee on workstation, and I need transfer file from my server to outside of company (to another server). I need to use https. There is any way I can do it...
1
by: john_aspinall | last post by:
Hi, I want to send an email form on an ASP page and make it secure/ encrypted when sending it to the recipient. Does anyone know how I might easily achieve this - or should I be going through...
0
by: marcello lussana | last post by:
Hi, I'm trying to send some xml data to a WSDL server. Here's my code: xmldata = "<oesystem<user login=\"nekhem\" password=\"one5076\" tpoa=\"\"<message id=\"1\"<textTest di messaggio 1...
6
by: aRTx | last post by:
I can't see a class, but i know i can send arguments see: https://myaccount.smsdiscount.com/clx/sendsms.php?username=xxxxxxxxxx&password=xxxxxxxxxx&from=xxxxxxxxxx&to=xxxxxxxxxx&text=xxxxxxxxxx ...
0
by: vagueante | last post by:
Hi, I have to connect to a webservice, and the data i have is: WSDL XML sample file (which is what i have to send to the webservice and with credentials, user and password tags). XSD file My...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.