国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1.1和2.0下進行https請求的不同實現

2019-11-18 16:53:40
字體:
來源:轉載
供稿:網友

今天做項目中進行https請求時遇到這樣的調試錯誤,內部錯誤:未能為 SSL/TLS 安全通道建立信任關系。錯誤頁面:根據驗證過程,遠程證書無效。經過分析,在瀏覽器中打開要進行一個安全確認。就是這個對話框引起的問題。在網上搜了一下一般的解決辦法,但是搜的內容比較少,現在在這里總結一下。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;

public partial class _Default : System.Web.UI.Page
{
    PRotected void Page_Load(object sender, EventArgs e)
    {
        //for 1.1 在2.0下ServicePointManager.CertificatePolicy已經過時
        //ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
        //for 2.0
        //ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://someurl");
        request.Method = "GET";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream receiveStream = response.GetResponseStream();
        StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
        Page.Response.Write(readStream.ReadToEnd());
        response.Close();
        readStream.Close();
    }
    //for 2.0
    public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {   //   Always   accept  
        return true;
    }
    //for 1.1
    internal class AcceptAllCertificatePolicy : ICertificatePolicy
    {
        public AcceptAllCertificatePolicy()
        {
        }

        public bool CheckValidationResult(ServicePoint sPoint, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest wRequest, int certProb)
        {
            //   Always   accept  
            return true;
        }
    }
}

http://m.survivalescaperooms.com/david8k/archive/2006/11/06/551911.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建水县| 古交市| 会东县| 城市| 云南省| 勐海县| 靖远县| 伊春市| 苍山县| 河津市| 大安市| 东莞市| 北京市| 虹口区| 双峰县| 洪泽县| 乌拉特中旗| 陇南市| 邻水| 固镇县| 湘阴县| 太原市| 南通市| 仙居县| 锦屏县| 北辰区| 赤壁市| 丁青县| 东乌珠穆沁旗| 浙江省| 肇州县| 武义县| 昆山市| 娱乐| 化隆| 仁怀市| 报价| 高清| 高清| 云南省| 泸西县|