-
-
Notifications
You must be signed in to change notification settings - Fork 11
HTTP POST Example
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.
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
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
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
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
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.