CURL Equivalent to POST JSON data using VBA

后端 未结 1 758
名媛妹妹
名媛妹妹 2021-01-07 09:32

I know this is similar to some previously asked questions, but something is still not working for me. How can the following command:

curl -X POST --data @s         


        
相关标签:
1条回答
  • 2021-01-07 10:19

    Try to make basic authorization as shown in the below example:

    Sub Test()
    
        sUrl = "https://xxxxxxx.waxlrs.com/TCAPI/statements"
        sUsername = "*******************"
        sPassword = "******************"
        sAuth = TextBase64Encode(sUsername & ":" & sPassword, "us-ascii")
        With CreateObject("WinHttp.WinHttpRequest.5.1")
            .Open "POST", sUrl, False
            .setRequestHeader "Content-Type", "application/json"
            .setRequestHeader "Authorization", "Basic " & sAuth
            .setRequestHeader "x-experience-api-version", "1.0.0"
            .send (stringJSON)
            apiWaxLRS = .responseText
        End With
    
    End Sub
    
    Function TextBase64Encode(sText, sCharset)
    
        Dim aBinary
    
        With CreateObject("ADODB.Stream")
            .Type = 2 ' adTypeText
            .Open
            .Charset = sCharset
            .WriteText sText
            .Position = 0
            .Type = 1 ' adTypeBinary
            aBinary = .Read
            .Close
        End With
        With CreateObject("Microsoft.XMLDOM").CreateElement("objNode")
            .DataType = "bin.base64"
            .NodeTypedValue = aBinary
            TextBase64Encode = Replace(Replace(.Text, vbCr, ""), vbLf, "")
        End With
    
    End Function
    
    0 讨论(0)
提交回复
热议问题