2017-02-27 27 views

Trả lời

2

Nếu bạn đang sử dụng NET 3.5.1, bạn có tùy chọn áp dụng hotfix rollup và áp dụng chỉnh sửa đăng ký để cho biết .NET sử dụng mặc định của hệ thống. More details here

Nếu bạn không cần sử dụng .NET 4.5 cho TLS 1.2 & 1.1 hỗ trợ và trên Windows Server 2008 R2 ở mức tối thiểu.

+0

Liên kết của bạn bị phá vỡ. – Cullub

5

Tôi đang sử dụng VS 2008 với .net 3.5.30729.4926. Tất cả tôi phải làm là:

Thêm hàng nhập khẩu:

Imports System.Security.Authentication 
Imports System.Net 

Thêm phần này vào mã của tôi (C#):

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

VB.net phiên bản:

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 Cảm ơn. Tôi nghi ngờ MS có thể trang bị thêm các hằng số trong các phiên bản cũ hơn của .net. –

+0

Điều này là tốt hơn so với câu trả lời khác vào lúc này - nó không phụ thuộc vào một liên kết bị hỏng ;-) – Cullub

+0

Mã này được đặt ở đâu? Trong một lớp học? hoặc global.asax? v.v. – Anna

Các vấn đề liên quan