473,883 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

POST HttpWebRequest to SLL Problem

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

private void mainHttpCalls(s tring postData)
HttpWebRequest objRequest1 ;
HttpWebRequest objRequest2 ;

HttpWebResponse objResponse1;
HttpWebResponse objResponse2;

StreamReader sr = null;
StreamWriter myWriter = null;

CookieCollectio n cookies = null;

string result;

clearTextboxes( );

Encoding utf8 = new UTF8Encoding();

ServicePointMan ager.Certificat ePolicy = new AcceptAllCertif icatePolicy();

string uri = cmbo_uri.Text;
txt_postdata.Te xt = postData;
postData = HttpUtility.Url Encode(postData );

// Get Logon Page
objRequest1 = (HttpWebRequest )System.Net.Htt pWebRequest.Cre ate(uri);
objRequest1.Met hod = "GET";
objRequest1.Con tentType = "text/html";
objRequest1.Coo kieContainer = new CookieContainer ();

// Display request header, cookies in left textbox displays
txt_requesthead er.Text = objRequest1.Hea ders.ToString() ;
foreach(Cookie c in
objRequest1.Coo kieContainer.Ge tCookies(objReq uest1.RequestUr i))
txt_requestcook ies.Text += c.Name + " = " + c.Value + "\n";

// Get the response from the request
objResponse1 = (HttpWebRespons e)objRequest1.G etResponse();

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

sr = new StreamReader(ob jResponse1.GetR esponseStream() , utf8);
result = sr.ReadToEnd();

objResponse1.Cl ose();

// Display response header, cookies in left textbox displays
txt_responsehea der.Text = objResponse1.He aders.ToString( );
foreach(object c in objResponse1.Co okies)
txt_responsecoo kies.Text += c.ToString();

txt_response.Te xt = result;
catch (Exception er1)
txt_errors.Text = er1.ToString();

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

result = string.Empty;
sr = null;

byte[] postcontent = utf8.GetBytes(p ostData);

objRequest2 = (HttpWebRequest )System.Net.Htt pWebRequest.Cre ate(uri);
objRequest2.Con tentType = "applicatio n/x-www-form-urlencoded";
objRequest2.Con tentLength = postcontent.Len gth;
objRequest2.Kee pAlive = true;
objRequest2.Coo kieContainer = new CookieContainer ();
if(cookies != null)
objRequest2.Coo kieContainer.Ad d(cookies);
objRequest2.Met hod = "POST";

// Sending the post request via stream writer

myWriter = new StreamWriter(ob jRequest2.GetRe questStream(), utf8);

myWriter.Write( utf8.GetString( postcontent),0, utf8.GetString( postcontent).Le n
myWriter.Flush( );
myWriter.Close( );

objResponse2 = (HttpWebRespons e)objRequest2.G etResponse();
StreamReader sr2 = new StreamReader(ob jResponse2.GetR esponseStream() ,
result = sr2.ReadToEnd() ;

objResponse2.Cl ose();
catch (Exception e2)
txt_errors.Text = "Error Writing Request: " + e2.Message + "\n" +
// Get the response from the request
// Display response header, cookies in righ textbox displays
txt_responsehea der2.Text = objResponse2.He aders.ToString( );
foreach(object c in objResponse2.Co okies)
txt_responsecoo kies2.Text += c.ToString();

txt_response2.T ext = result;

catch (Exception re)
txt_errors2.Tex t = "Error Getting Response: " + "\n" + re.ToString();
// Display request header, cookies in righ textbox displays
txt_requesthead er2.Text = objRequest2.Hea ders.ToString() ;
foreach(Cookie c in
objRequest2.Coo kieContainer.Ge tCookies(objReq uest2.RequestUr i))
txt_requestcook ies2.Text += c.Name + " = " + c.Value + "\n";


sealed class AcceptAllCertif icatePolicy : ICertificatePol icy
public bool CheckValidation Result(ServiceP oint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProb lem)
// Just accept.
return true;

Jul 19 '05 #1
0 3429

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

Similar topics

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 establish secure channel for SSL/TLS" private void mainHttpCalls(string postData) { HttpWebRequest objRequest1 ; HttpWebRequest objRequest2 ;
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) WebRequest.Create("http://mysite.com/index.php"); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; string postData = "var=value1&var2=value2"
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. string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains a form string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called by get_Url upon submit
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" value="Merchant Name"> <input type="hidden" name="OrderID" value="Unique OrderID value"> <input type="hidden" name="email" value="Customers email address (OPTIONAL)">
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 tools like ieHTTPHeaders v1.6, and I perform a normal login (using the normal website), I see that the viewstate is __VIEWSTATE=dDwxMzU4OTE3NTA2Ozs%2BTK88jS63JXN181X3N8zKivua8co%3D&txt_username=xxx&txt_password=xxxxxx&btn_login=Login. When I...
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 and the post data is corect. But when I sniff the http packet it contains not post data and he response is not the same. Here are the sniffed post packets. POST from IE6 (Request-Line):POST /Estd/Default.aspx?C=BRE&E=P&L=FRA&Ref=20051122161245...
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 one post for every 10 seconds the client start getting error 403 'forbidden' from the webserver after a short period of time. The webserver is IIS. The choking of the client/server communication when doing high frequency posting is due to that we...
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 advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST - Webclient=================================
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 problem. I'm using this code in a ASP.NET 2.0 application just in case that matters, maybe someone knows a better way to do this?
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.