gpt4 book ai didi

c# - 如何在 .Net 3.5 框架中实现安全协议(protocol) TLS 1.2

转载 作者:可可西里 更新时间:2023-11-01 08:37:33 26 4
gpt4 key购买 nike

由于 Paypal 更新了他们的响应,我需要在 .NET 3.5 框架上的现有应用程序中将安全协议(protocol) TLS 更新为 v1.2。在现有代码中更新它需要做哪些更改,我无法将应用程序更新到更新的框架。

最佳答案

我正在使用 VS 2008 和 .net 3.5.30729.4926。我所要做的就是:

添加导入:

Imports System.Security.Authentication
Imports System.Net

将此添加到我的代码 (C#) 中:

public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;

VB.net 版本:

Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)
Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12

Dim wbrq As HttpWebRequest
Dim wbrs As HttpWebResponse
Dim sw As StreamWriter
Dim sr As StreamReader
Dim strResult As String

'Create a new HttpWebRequest object.
wbrq = WebRequest.Create(strURL)
wbrq.Method = "POST"
wbrq.ContentLength = DataString.Length
wbrq.ContentType = "application/x-www-form-urlencoded"

'upload data
sw = New StreamWriter(wbrq.GetRequestStream)
sw.Write(DataString)
sw.Close()

'get response
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetResponseStream)
strResult = sr.ReadToEnd.Trim
sr.Close()

关于c# - 如何在 .Net 3.5 框架中实现安全协议(protocol) TLS 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42484888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com