Question

Is there anyone that can point me in the right direction. I have to connect to an https url via visual basic 6.0 and issue JSON's as transactions. The JSON classes are finished but I have no clue how to establish this connection. I have been all over the web doing research and have found nothing. No this is not a homework assignment. Been happily developing for years on the application side and now expanding to new horizons. I really need to see a basic example if anyone could provide that. Any help is appreciated.

Public Function OpenPostHttpRequest() As Boolean
    Dim bReturn As Boolean
    bReturn = False
    If Not (m_sUrl = "") Then
        On Error GoTo ErrorHandler
        m_HttpRequest.Open "Post", m_sUrl & m_sEAuthentificationValue & "/devices/data" & "?authentification_token=" & m_sEAuthentificationValue & "auth=" & m_sEAuthValue, False
        m_HttpRequest.SetRequestHeader "Content-Type", "text/JSON; charset = utf-8"
        m_HttpRequest.Send m_sPost
    Else
        bReturn = False
    End If
    OpenPostHttpRequest = bReturn
    Exit Function

ErrorHandler:
    Dim E As ErrObject: Set E = Err

    OpenPostHttpRequest = False
    m_HttpRequest.Abort
End Function

The I cut and pasted the url from PostMan and the Json works in Postman. Thanks guys. This is turning into a learning experience

Was it helpful?

Solution

Instead of creating a new class to handle the transaction we used WinHttpRequest directly. Went off with out a hitch. It handled the transistion to https just fine.

Private Sub cmdSend_Click()
Dim Http As WinHttp.WinHttpRequest
Dim sUrl As String
Dim sResponse As String

On Error GoTo ErrorHandler
    Set Http = New WinHttp.WinHttpRequest
    sUrl = "https://sandbox.appcard.com/v2/<apiKey>/devices/data?"
    sUrl = sUrl & "authentication_token=<apiKey>&auth=<auth>"
    Http.Open "POST", sUrl, False
    Http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"

    Http.Send (Text1.Text)
    m_edtUrlResponse.Text = Http.ResponseText
    Set Http = Nothing
    Exit Sub
ErrorHandler:
    Dim E As ErrObject: Set E = Err

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top