国产探花免费观看_亚洲丰满少妇自慰呻吟_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://www.survivalescaperooms.com/david8k/archive/2006/11/06/551911.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 图片| 砚山县| 苏尼特左旗| 锡林浩特市| 万全县| 门源| 延安市| 象山县| 兴安县| 临夏市| 太保市| 得荣县| 沾化县| 芒康县| 贵港市| 灵璧县| 商南县| 静乐县| 夏邑县| 东宁县| 龙川县| 芦山县| 阿拉善左旗| 会同县| 海丰县| 鄂州市| 吉安县| 曲松县| 琼海市| 化州市| 聂拉木县| 外汇| 咸阳市| 蒙自县| 宝清县| 元氏县| 水城县| 旬阳县| 洮南市| 贵定县| 黄山市|