472,794 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 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 26899
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

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.