zoukankan      html  css  js  c++  java
  • 解决12306.cn网站验证码获取提示“基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系“的问题


    https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=sjrand&0.8967564508222368

    这是图片的访问网址

    大家看清楚了,是Https的网站,也就是说是需要证书才能访问了,这个只要获取证书就行了,方法如下
    先直接在浏览器输入这个网站然后回车



    然后再单击如下图片位置



    会出现如下界面



    我我选择详细信息里面的 复制到文件



    在下一步之后选择第二项目,就是Base64编码



    给证书选择一个存放的位置这也是一会儿写代码时需要的位置



    然后下一步单击完成就行了



    看到这个时表示你成功了。
    使用我的Httphelper的代码如下

    /// <summary>
    /// 字节数组生成图片
    /// </summary>
    /// <param name="Bytes">字节数组</param>
    /// <returns>图片</returns>
    private Image byteArrayToImage(byte[] Bytes)
    {
        MemoryStream ms = new MemoryStream(Bytes);
     
        Image outputImg = Image.FromStream(ms);
        return outputImg;
     
    }
     
    private void Form1_Load(object sender, EventArgs e)
    {
        HttpHelper http = new HttpHelper();
        HttpItem item = new HttpItem()
        {
            URL = "https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=sjrand&0.8967564508222368",//URL     必需项    
            Method = "get",//URL     可选项 默认为Get   
            CerPath = "D:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数      
            ResultType = ResultType.Byte
        };
        HttpResult result = http.GetHtml(item);
        //获取到的图片
        Image im = byteArrayToImage(result.ResultByte);
        pictureBox1.Image = im;
    }

    执行效果如下



    呵呵到这里问题就解决了。

    大家感觉可以的话给推荐一下吧 或者给点建议也可以。非常感谢!

    这上面是教大家怎么样使用Https网站的证书,如果单纯的说这个12306的网站是不需要的,因为他可以通过Http直接访问

    http://dynamic.12306.cn/otsweb/passCodeAction.do?rand=sjrand&0.8967564508222368

    就是上面的地址也是一样可以访问的。呵呵

    原文地址:http://www.sufeinet.com/thread-4270-1-1.html

  • 相关阅读:
    [leedcode 77] Combinations
    [leedcode 76] Minimum Window Substring
    [leedcode 75] Sort Colors
    [leedcode 74] Search a 2D Matrix
    [leedcode 73] Set Matrix Zeroes
    [leedcode 71] Simplify Path
    [leedcode 70] Climbing Stairs
    [leedcode 69] Sqrt(x)
    [leedcode 67] Add Binary
    HDU1027-Ignatius and the Princess II(全排列问题next_permutation函数的使用)
  • 原文地址:https://www.cnblogs.com/sufei/p/3195600.html
Copyright © 2011-2022 走看看