SSL httpwebrequest in C # "cocould not create SSL/TLS Secure Channel

Source: Internet
Author: User
Re: SSL httpwebrequest in C # "cocould not create SSL/TLS secure channel ."
Posted on:22 Jan 2009 Accepted answer  

OK so after 6 months I have solved this problem!

It was several things, the other server (A webmethods Integration Server) is a little picky about what kinds of protocols it accepts. So after some fiddling around here are the two things that fixed it:

Servicepointmanager. securityprotocol = securityprotocoltype. ssl3;

And

Req. protocolversion = httpversion. version10;

 

So the whole code is:

Servicepointmanager. expect100continue = true;

Servicepointmanager. securityprotocol = securityprotocoltype. ssl3;

Httpwebrequest Req = (httpwebrequest) webrequest. Create ("https: // websiteurl: 9000 ");

// Header settings

Req. method = "Post"; // POST method

Req. contenttype = "text/XML"; // content type

Req. keepalive = false;

Req. protocolversion = httpversion. version10;

// Certificate with Private Key

X509certificate2 Cert = new x509certificate2 ("Cert. Der", "password ");

Req. clientcertificates. Add (CERT );

Req. preauthenticate = true;

String xml = "Test message" // reader. readtoend ();

Byte [] buffer = encoding. ASCII. getbytes (XML );

Req. contentlength = buffer. length;

// Wrap the request stream with a text-based writer

Stream writer = Req. getrequeststream ();

// Write the XML text into the stream

Writer. Write (buffer, 0, buffer. Length );

Writer. Close ();

Webresponse RSp = Req. getresponse ();

Streamreader responsestream = new streamreader (RSP. getresponsestream ());

 

Hope this helps someone else in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.