472,796 Members | 1,459 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,796 software developers and data experts.

POST HttpWebRequest to SLL Problem

TJO
Can someone at MS please reply to this. I am trying to post data so a web
form via ssl with the following code. I keep getting this error: "The
underlying connection was closed: Could not establish secure channel for
SSL/TLS"

private void mainHttpCalls(string postData)
{
HttpWebRequest objRequest1 ;
HttpWebRequest objRequest2 ;

HttpWebResponse objResponse1;
HttpWebResponse objResponse2;

StreamReader sr = null;
StreamWriter myWriter = null;

CookieCollection cookies = null;

string result;

clearTextboxes();

Encoding utf8 = new UTF8Encoding();

ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();

string uri = cmbo_uri.Text;
txt_postdata.Text = postData;
postData = HttpUtility.UrlEncode(postData);

// Get Logon Page
objRequest1 = (HttpWebRequest)System.Net.HttpWebRequest.Create(u ri);
objRequest1.Method = "GET";
objRequest1.ContentType = "text/html";
objRequest1.CookieContainer = new CookieContainer();

// Display request header, cookies in left textbox displays
txt_requestheader.Text = objRequest1.Headers.ToString();
foreach(Cookie c in
objRequest1.CookieContainer.GetCookies(objRequest1 .RequestUri))
{
txt_requestcookies.Text += c.Name + " = " + c.Value + "\n";
}

// Get the response from the request
try
{
objResponse1 = (HttpWebResponse)objRequest1.GetResponse();

// Save the session and other cookies from the initial request.
if(objResponse1.Cookies.Count > 0)
cookies = objResponse1.Cookies;

sr = new StreamReader(objResponse1.GetResponseStream(), utf8);
result = sr.ReadToEnd();

sr.Close();
objResponse1.Close();

// Display response header, cookies in left textbox displays
txt_responseheader.Text = objResponse1.Headers.ToString();
foreach(object c in objResponse1.Cookies)
{
txt_responsecookies.Text += c.ToString();
}

txt_response.Text = result;
}
catch (Exception er1)
{
txt_errors.Text = er1.ToString();
return;
}

// ******************** Now post the data **************************
// ******************** Now post the data **************************

result = string.Empty;
sr = null;

byte[] postcontent = utf8.GetBytes(postData);

objRequest2 = (HttpWebRequest)System.Net.HttpWebRequest.Create(u ri);
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.ContentLength = postcontent.Length;
objRequest2.KeepAlive = true;
objRequest2.CookieContainer = new CookieContainer();
if(cookies != null)
objRequest2.CookieContainer.Add(cookies);
objRequest2.Method = "POST";

// Sending the post request via stream writer
try
{

myWriter = new StreamWriter(objRequest2.GetRequestStream(), utf8);

myWriter.Write(utf8.GetString(postcontent),0,utf8. GetString(postcontent).Len
gth);
myWriter.Flush();
myWriter.Close();

objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
StreamReader sr2 = new StreamReader(objResponse2.GetResponseStream(),
utf8);
result = sr2.ReadToEnd();

objResponse2.Close();
sr2.Close();
}
catch (Exception e2)
{
txt_errors.Text = "Error Writing Request: " + e2.Message + "\n" +
e2.ToString();
return;
}
// Get the response from the request
try
{
// Display response header, cookies in righ textbox displays
txt_responseheader2.Text = objResponse2.Headers.ToString();
foreach(object c in objResponse2.Cookies)
{
txt_responsecookies2.Text += c.ToString();
}

txt_response2.Text = result;

}
catch (Exception re)
{
txt_errors2.Text = "Error Getting Response: " + "\n" + re.ToString();
}
// Display request header, cookies in righ textbox displays
txt_requestheader2.Text = objRequest2.Headers.ToString();
foreach(Cookie c in
objRequest2.CookieContainer.GetCookies(objRequest2 .RequestUri))
{
txt_requestcookies2.Text += c.Name + " = " + c.Value + "\n";
}

}

sealed class AcceptAllCertificatePolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
// Just accept.
return true;
}

}
Jul 19 '05 #1
0 3314

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: TJO | last post by:
Can someone at MS please reply to this. I am trying to post data so a web form via ssl with the following code. I keep getting this error: "The underlying connection was closed: Could not...
4
by: supster | last post by:
Hello, I am trying to use HttpWebRequest to simulate sending some POST data from a form to a PHP script. I have accomplished this using: HttpWebRequest req = (HttpWebRequest)...
5
by: Tammy | last post by:
Hi, I have an aspx app which needs to post data to a form and read the response. I am confused on whether I should be using the get_url using "POST" method or the post_url using "GET" method. ...
7
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant"...
0
by: WIWA | last post by:
Hi, I want to login to a password protected website and fetch the content of the page behind. I have based my code on http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use...
1
by: logik3x | last post by:
I'm developping a program to automate the submisson of grades to a website called omnivox.ca (http://brebeuf.omnivox.ca). My problem is that I can't get the login working. I get the cookie right...
3
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to...
4
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great...
0
by: barrybevel | last post by:
Hi, I'm trying to login to the www.vodafone.ie website using HttpWebRequest. It works fine with IE/Firefox and the .NET Web Control too, just not with my code. I think it's a redirect 302...
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...
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 ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.