狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開(kāi)發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C# HTTPS請(qǐng)求“請(qǐng)求被中止: 未能創(chuàng)建 SSL/TLS 安全通道”

admin
2023年5月23日 9:52 本文熱度 1725

HttpWebRequest 請(qǐng)求https接口,一直提示未能創(chuàng)建 SSL/TLS 安全通道! 證書(shū)驗(yàn)證創(chuàng)建委托一直返回true 也不行。
因?yàn)槭菃蜗蛘J(rèn)證,所以這個(gè)肯定沒(méi)啥問(wèn)題,只能繼續(xù)查資料了。

注意:如果是雙向認(rèn)證就需要加載證書(shū)才可以通信。

private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

{

return true;

}

我用的是NET Farmwork 4,查了資料才知道根本不支持TLS,最高就到SSL3,所以我換到了NET Farmwork 4.5,完美解決。

完整代碼:

private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";

private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

{

return true;

}

public static string HttpsPost(string url, string postData)

{

Stream outstream = null;

Stream instream = null;

StreamReader sr = null;

HttpWebResponse response = null;

HttpWebRequest request = null;

Encoding encoding = Encoding.GetEncoding("utf-8");  //選擇編碼字符集

byte[] data = encoding.GetBytes(postData); //轉(zhuǎn)換為bytes數(shù)據(jù)

// 準(zhǔn)備請(qǐng)求...

try

{

// 設(shè)置參數(shù)

if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))

{

ServicePointManager.ServerCertificateValidationCallback =

new RemoteCertificateValidationCallback(CheckValidationResult);

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072; //必須加上這一句,根據(jù)需要更改值

request = WebRequest.create(url) as HttpWebRequest;

request.ProtocolVersion = HttpVersion.Version10;

}

else

{

request = WebRequest.create(url) as HttpWebRequest;

}

CookieContainer cookieContainer = new CookieContainer();

request.CookieContainer = cookieContainer;

request.AllowAutoRedirect = true;

request.Timeout = 30*1000;  //30S

request.ContinueTimeout = 30 * 1000;

request.Method = "POST";

request.ContentType = "application/json";

request.ContentLength = data.Length;

request.UserAgent = DefaultUserAgent;

// request.TransferEncoding = encoding.HeaderName;

outstream = request.GetRequestStream();

outstream.Write(data, 0, data.Length);

outstream.Close();

//發(fā)送請(qǐng)求并獲取相應(yīng)回應(yīng)數(shù)據(jù)

response = request.GetResponse() as HttpWebResponse;

//直到request.GetResponse()程序才開(kāi)始向目標(biāo)網(wǎng)頁(yè)發(fā)送Post請(qǐng)求

instream = response.GetResponseStream();

sr = new StreamReader(instream, encoding);

//返回結(jié)果網(wǎng)頁(yè)(html)代碼

string content = sr.ReadToEnd();

string err = string.Empty;

return content;

}

catch (Exception ex)

{

string err = ex.Message;

return string.Empty;

}

}

親測(cè)有效。


該文章在 2023/5/23 9:52:52 編輯過(guò)
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專(zhuān)業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車(chē)隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開(kāi)發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類(lèi)企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷(xiāo)售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶(hù)的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved