473,783 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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
try
{
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();

sr.Close();
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();
return;
}

// *************** ***** 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
try
{

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

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

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

objResponse2.Cl ose();
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_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 3418

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

Similar topics

0
335
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 ;
4
40919
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"
5
17392
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
7
4264
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)">
0
3886
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...
1
3184
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...
3
4931
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...
4
12712
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=================================
0
12790
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?
0
9643
marktang
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...
0
9480
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,...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
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...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
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...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.