0

In CURL, I can use this line

curl --data 'DataToBeSent' https://example.com/resource.cgi

I am struggling to convert such line to be used in VBA and this is my try till now

Sub POST_Method_Example()
Dim myMessage As String

myMessage = "DataToBeSent"

With CreateObject("MSXML2.ServerXMLHTTP")
    .Open "POST", "https://example.com/resource.cgi"

    .setRequestHeader "Content-Type", "multipart/form-data; boundary==------------------------d74496d66958873e"
    .send sData(myMessage)
    Debug.Print .ResponseText
End With
End Sub

But this throws an error at the json response. How can I make this works for VBA?

I can get it work on postman by assigning the url and in Body tab I selected "form-data" and assign KEY: text and VALUE: DataToBeSent This returns a successful response.

1
  • @QHarr Welcome back. Waiting for your experience. Commented Mar 29, 2020 at 8:15

1 Answer 1

2

See multipart/form-data for when to use.

Sub POST_Method_Example()

    With CreateObject("MSXML2.ServerXMLHTTP")
        .Open "POST", "https://example.com/resource.cgi"
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .send "text=Data to be sent"
        Debug.Print .ResponseText
    End With

End Sub

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for great help. Can you have a look at this link, please? stackoverflow.com/questions/60890492/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.