-
-
Notifications
You must be signed in to change notification settings - Fork 11
HTTP POST Example
##Form encoding
HTML forms may be encoded as either multipart/form-data or application/x-www-form-urlencoded. multipart/form-data forms can contain files for upload, whereas application/x-www-form-urlencoded forms can contain only "Key=Value" strings. As such, to have the cURLClient class use application/x-www-form-urlencoded pass a String array to the Post method; to use multipart/form-data pass a Dictionary.
#Using multipart/form-data
##Synchronous
This example sends a synchronous HTTP POST request containing a multipart/form-data form with two string elements and one file element.
Dim cURL As New cURLClient
Dim form As New Dictionary
form.Value("Test1") = "TestValue1"
form.Value("Test2") = "TestValue2"
Dim f As FolderItem = GetOpenFolderItem("")
form.Value("file") = f
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-data form with two string elements and one file element.
Dim cURL As New cURLClient
Dim form As New Dictionary
form.Value("Test1") = "TestValue1"
form.Value("Test2") = "TestValue2"
Dim f As FolderItem = GetOpenFolderItem("")
form.Value("file") = f
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
MsgBox(libcURL.FormatError(curl.LastError))
End If#Using application/x-www-form-urlencoded
##Synchronous
This example sends a synchronous HTTP POST request containing a application/x-www-form-urlencoded form with two elements.
Dim cURL As New cURLClient
Dim form() As String
form.Append("Test1=TestValue1")
form.Append("Test2=TestValue2")
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 an application/x-www-form-urlencoded form with two elements.
Dim cURL As New cURLClient
Dim form() As String
form.Append("Test1=TestValue1")
form.Append("Test2=TestValue2")
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
MsgBox(libcURL.FormatError(curl.LastError))
End IfWiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-26 Andrew Lambert, offered under the CC BY-SA 3.0 License.