使用vb 6.0建立与服务器的https连接

时间:2014-03-25 13:47:27

标签: https vb6 winsock

有没有人可以指出我正确的方向。我必须通过visual basic 6.0连接到https网址并发布JSON作为交易。 JSON类已完成,但我不知道如何建立此连接。我一直在网上做研究,一无所获。不,这不是家庭作业。多年来在应用方面愉快地开发,现在正在扩展到新的视野。 如果有人能提供,我真的需要看一个基本的例子。任何帮助表示赞赏。

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

我剪切并粘贴了PostMan的网址,Json在Postman工作。多谢你们。这正在变成一种学习体验

1 个答案:

答案 0 :(得分:1)

我们没有创建一个新类来处理事务,而是直接使用WinHttpRequest。顺便溜走了。它处理转换到https就好了。

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