1

Given a Curl command :

curl https://URL
-u xxxxxxxxxxxxxxxxxxxxxx:
-X POST
-F "source_file=@/tmp/my.doc"
-F "DoSomething=checkit"

The expected result is a Json string. How can this be used in VBA Excel macro utilizing a "WinHttp.WinHttpRequest.5.1" object. Is the file "my.doc" transfered by name or by a Byte array ?

I manged to convers a simple Curl command:

curl https://URL
-u xxxxxxxxxxxxxxxxxxxxxx:

into the following code which works fine.

With CreateObject("WinHttp.WinHttpRequest.5.1")
    .Open "GET", URL, False
    .SetCredentials "xxxxxxxxxxxxxxxxxxxxxx", "", 0
    .send
    If .Status <> 200 Then
        If MsgBox(.responseText, vbOKOnly + vbCritical, "Error") = vbOK Then
            Exit Sub
        End If
    Else
        ss = .responseBody
        BodyData = StrConv(ss, vbUnicode)
        Set Json = JsonConverter.ParseJson(BodyData)
    End If

The same is needed for the above Curl command. Please help .

ckosh
  • 7
  • 2

1 Answers1

0

You'll need to modify and add a few more parameters for the POST request. Try adapting using this example, and let us know what the errors are if you get any.

POST request with win http

Peyter
  • 474
  • 3
  • 14