Skip to content
Andrew Lambert edited this page Jun 12, 2015 · 22 revisions

##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 If

Clone this wiki locally