Skip to content
Andrew Lambert edited this page Jun 13, 2016 · 22 revisions

##Form encoding HTML 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.


#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") = "TestValue1"
  form.Value("Test2") = "TestValue2"
  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") = "TestValue1"
  form.Value("Test2") = "TestValue2"
  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
    MsgBox(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
    MsgBox(libcURL.FormatError(curl.LastError))
  End If
Clone this wiki locally