• SSL HttpWebRequest in C# "Could not create SSL/TLS secure channel


    Re: SSL HttpWebRequest in C# "Could not create SSL/TLS secure channel."
      Posted on: 22 Jan 2009  Accepted Answer   0   

    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.

  • 相关阅读:
    IT知识构架与操作系统简介
    read与for循环语句
    shell基础练习题
    shell 100以内加法
    shell
    python学习第一日
    shell脚本基本介绍
    bash的基本特性
    Linux习题
    Linux基本命令
  • 原文地址:https://www.cnblogs.com/bayonetxxx/p/2499719.html
Copyright © 2020-2023  润新知