解決12306.cn網站驗證碼獲取提示「基礎鏈接已經關閉: 未能爲 SSL/TLS 安全通道創建信任關係「的問題


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

這是圖片的訪問網址html

你們看清楚了,是Https的網站,也就是說是須要證書才能訪問了,這個只要獲取證書就好了,方法以下
先直接在瀏覽器輸入這個網站而後回車web



而後再單擊以下圖片位置數組



會出現以下界面瀏覽器



我我選擇詳細信息裏面的 複製到文件網站



在下一步以後選擇第二項目,就是Base64編碼編碼



給證書選擇一個存放的位置這也是一下子寫代碼時須要的位置spa



而後下一步單擊完成就好了code



看到這個時表示你成功了。
使用個人Httphelper的代碼以下orm

/// <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;
}

執行效果以下htm



呵呵到這裏問題就解決了。

你們感受能夠的話給推薦一下吧 或者給點建議也能夠。很是感謝!

這上面是教你們怎麼樣使用Https網站的證書,若是單純的說這個12306的網站是不須要的,由於他能夠經過Http直接訪問

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

就是上面的地址也是同樣能夠訪問的。呵呵

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

相關文章
相關標籤/搜索