Как разместить JSON для безопасного API-интерфейс REST в VB.NET компактный 3.5
Привет,
Я действительно борется с проводки JSON для безопасного API-интерфейс REST в VB.net компактный 3.5 приложения. Ниже приведен первый фрагмент кода, который я попробовал, и я получаю ошибку "не удалось установить безопасный канал для SSL/TLS".
Imports Newtonsoft.Json Imports System.Net Imports System.IO Imports System.Text Public Class Form1 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Create Json of Data for Transmition Dim SendData As String Dim NetSuiteRequest As New NetSuite.CreateBin.Request Dim BinList As New List(Of NetSuite.CreateBin.RequestProperties) Dim Bin As New NetSuite.CreateBin.RequestProperties Bin.BinNumber = "D20.A01.01.A" Bin.RecordType = "create" Bin.RecordType = "bin" BinList.Add(Bin) NetSuiteRequest.request = BinList SendData = JsonConvert.SerializeObject(NetSuiteRequest, Formatting.Indented) '********************************************************************************** Dim request As HttpWebRequest Dim response As HttpWebResponse = Nothing Dim reader As StreamReader Dim address As Uri Dim byteData() As Byte Dim postStream As Stream = Nothing address = New Uri("https://---------------------------Sorry Cant Show URL--------------") ' Create the web request request = DirectCast(WebRequest.Create(address), HttpWebRequest) ' Set type to POST request.Method = "POST" request.ContentType = "application/json; charset=UTF-8" request.Accept = "application/json" 'Add authentication to request request.Credentials = New NetworkCredential("UserName", "Password") ' Create a byte array of the data we want to send byteData = UTF8Encoding.UTF8.GetBytes(SendData.ToString()) ' Set the content length in the request headers request.ContentLength = byteData.Length ' Write data Try postStream = request.GetRequestStream() postStream.Write(byteData, 0, byteData.Length) Finally If Not postStream Is Nothing Then postStream.Close() End Try Try ' Get response response = DirectCast(request.GetResponse(), HttpWebResponse) ' Get the response stream into a reader reader = New StreamReader(response.GetResponseStream()) ' Console application output Console.WriteLine(reader.ReadToEnd()) Finally If Not response Is Nothing Then response.Close() End Try End Sub End Class
Что я уже пробовал:
Я попробовал использовать Rebex.net чтобы преодолеть эту проблему и этот код, который я придумал, но он тоже не работает.
Imports Newtonsoft.Json Imports System.Net Imports System.IO Imports System.Text Imports Rebex.Net Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Create Json of Data for Transmition Dim SendData As String Dim NetSuiteRequest As New NetSuite.CreateBin.Request Dim BinList As New List(Of NetSuite.CreateBin.RequestProperties) Dim Bin As New NetSuite.CreateBin.RequestProperties Bin.BinNumber = "D20.A01.01.A" Bin.RecordType = "create" Bin.RecordType = "bin" BinList.Add(Bin) NetSuiteRequest.request = BinList SendData = JsonConvert.SerializeObject(NetSuiteRequest, Formatting.Indented) '***************************************************************************************** Dim creator = New HttpRequestCreator() creator.Settings.SslAllowedVersions = TlsVersion.Any Dim Address As New Uri("https://---------------------------Sorry Cant Show URL--------------") Dim Request As WebRequest = creator.Create(Address) Request.Method = "POST" Request.ContentType = "application/json; charset=UTF-8" Request.Credentials = New NetworkCredential("UserName", "Password") '************************************************************************************************************ Dim byteData() As Byte Dim postStream As Stream = Nothing Dim Response As WebResponse Dim reader As StreamReader ' Create a byte array of the data we want to send byteData = UTF8Encoding.UTF8.GetBytes(SendData.ToString()) ' Set the content length in the request headers Request.ContentLength = byteData.Length ' Write data Try postStream = Request.GetRequestStream() postStream.Write(byteData, 0, byteData.Length) Finally If Not postStream Is Nothing Then postStream.Close() End Try Try ' Get response Response = DirectCast(Request.GetResponse(), WebResponse) ' Get the response stream into a reader reader = New StreamReader(response.GetResponseStream()) ' Console application output Console.WriteLine(reader.ReadToEnd()) Finally If Not response Is Nothing Then response.Close() End Try End Sub End Class
Вся помощь очень ценится.
Овации,
Джоэл Стин.
Kornfeld Eliyahu Peter
Подробности исключения?
Вы проверяли наличие проблем с сертификатами?
Aneets
Спасибо за Ваш ответ Корнфельд Элиягу Питер,
Исключение из первого фрагмента кода было "не удалось установить безопасный канал для SSL/TLS".
Как проверить наличие проблем с сертификатами?
Овации,
Джоэл Стин.