Click here to Skip to main content
14,773,751 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm a veteran developer, who, through necessity, has returned to "the tools" after 20 years in IT management.

I'm currently developing a small application in Visual Basic (Visual Studio 2013) that converts very large .CSV files into JSON format and sends the data (customer info)to a 3rd party via their API.

I've written the fairly simple UI and the code to do the conversion to JSON and that all works fine, but I'm having no luck with connectivity to the 3rd party API.

I've tested the JSON code via a test driver on their portal back can't even get an error code back when I try it through VB.

At this stage, all I'm trying to do is login inti the API (using creds provided by the 3rd party) and get a Bearer Token in return.

Any help welcome!

Paul

What I have tried:

This is the code I'm using:

The parameters are:
uri           = endpoint URL (as URI class)
jsonDataBytes = JSON format user creds encoded in UTF8
contentType   = "application/json" 
method        = "POST"

It fails at Using responseStream = request.GetResponse.GetResponseStream

With the error message "The request was aborted: Could not create SSL/TLS secure channel"
Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
    Dim response As String = ""
    Dim request As WebRequest

    request = WebRequest.Create(uri)
    request.ContentLength = jsonDataBytes.Length
    request.ContentType = contentType
    request.Method = method

    Try
        Using requestStream = request.GetRequestStream
            requestStream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
            requestStream.Close()

            Using responseStream = request.GetResponse.GetResponseStream
                Using reader As New StreamReader(responseStream)
                    response = reader.ReadToEnd()
                End Using
            End Using
        End Using
    Catch ex As Exception
        AddLogEntry("ERROR! - " & ex.Message)
    End Try

    Return response

End Function
Posted
Updated 12-Jan-21 7:15am
v3

1 solution

You probably need to upgrade to a newer Visual Studio version and .NET version, see:
TLS 1.2 and .NET Support: How to Avoid Connection Errors[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900