2017-02-27 148 views

回答

2

如果您在NET 3.5.1上,您可以選擇應用匯總修補程序並應用註冊表編輯來告訴.NET使用系統默認值。 More details here

如果您需要使用.NET 4.5 for TLS 1.2 & 1.1支持,並且至少需要在Windows Server 2008 R2上運行。

+0

您的鏈接被打破。 – Cullub

5

我使用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() 
+1

@Cullub謝謝。我懷疑MS可能會在舊版本的.net中翻新常量。 –

+0

這比現在的其他答案要好 - 它不依賴於斷開的鏈接;-) – Cullub

+0

代碼中的位置是放在哪裏的?在一堂課上?或global.asax?等等? – Anna