HTTP POST Example - charonn0/RB-libcURL GitHub Wiki
Form encoding
HTTP forms may be encoded as either multipart/form-data ("multipart") or application/x-www-form-urlencoded ("URL encoded"). Multipart forms can contain files for upload whereas URL encoded forms can contain only "Key=Value" strings. As such, to have the cURLClient class use a URL encoded form pass a String array to the Post method; to use a multipart form pass a Dictionary.
To POST other kinds of data, for example a JSON payload, use upload semantics (i.e. PUT) and override the request method.
Using a multipart form
Synchronous
This example sends a synchronous HTTP POST request containing a multipart form with two string elements and one file element.
Dim curl As New cURLClient
Dim form As New Dictionary
form.Value("Test1") = "Test Value 1"
form.Value("Test2") = "Test Value 2"
form.Value("file") = GetOpenFolderItem("")
If Not curl.Post("http://www.example.com/submit.php", form) Then
MsgBox(libcURL.FormatError(curl.LastError))
End If
Asynchronous
This example sends an asynchronous HTTP POST request containing a multipart form with two string elements and one file element.
Dim curl As New cURLClient
Dim form As New Dictionary
form.Value("Test1") = "Test Value 1"
form.Value("Test2") = "Test Value 2"
form.Value("file") = GetOpenFolderItem("")
curl.Post("http://www.example.com/submit.php", form)
Do Until curl.IsTransferComplete
App.DoEvents() 'async transfers require an event loop!
Loop
If curl.LastError <> 0 Then
Print(libcURL.FormatError(curl.LastError))
End If
Using a URL encoded form
Synchronous
This example sends a synchronous HTTP POST request containing a URL encoded form with two elements.
Dim curl As New cURLClient
Dim form() As String
form.Append("Test1=Test%20Value%201")
form.Append("Test2=Test%20Value%202")
If Not curl.Post("http://www.example.com/submit.php", form) Then
MsgBox(libcURL.FormatError(curl.LastError))
End If
Asynchronous
This example sends an asynchronous HTTP POST request containing a URL encoded form with two elements.
Dim curl As New cURLClient
Dim form() As String
form.Append("Test1=Test%20Value%201")
form.Append("Test2=Test%20Value%202")
curl.Post("http://www.example.com/submit.php", form)
Do Until curl.IsTransferComplete
App.DoEvents() 'async transfers require an event loop!
Loop
If curl.LastError <> 0 Then
Print(libcURL.FormatError(curl.LastError))
End If