Skip to content

libcURL.cURLClient.Post

Andrew Lambert edited this page Nov 8, 2023 · 30 revisions

Method Signatures

 Function Post(URL As String, PostFields() As String, WriteTo As Writeable = Nil) As Boolean
 Function Post(URL As String, FormData As libcurl.MultipartForm, WriteTo As Writeable = Nil) As Boolean
 Function Post(URL As String, FormData As libcurl.MIMEMessage, WriteTo As Writeable = Nil) As Boolean
 Function Post(URL As libcURL.URLParser, FormData As libcurl.MIMEMessage, WriteTo As Writeable = Nil) As Boolean
 Function Post(URL As libcURL.URLParser, FormData As libcurl.MultipartForm, WriteTo As Writeable = Nil) As Boolean
 Function Post(URL As libcURL.URLParser, PostFields() As String, WriteTo As Writeable = Nil) As Boolean
 Sub Post(URL As String, PostFields() As String, WriteTo As Writeable = Nil)
 Sub Post(URL As String, FormData As libcurl.MultipartForm, WriteTo As Writeable = Nil)
 Sub Post(URL As String, FormData As libcurl.MIMEMessage, WriteTo As Writeable = Nil)
 Sub Post(URL As libcURL.URLParser, FormData As libcurl.MIMEMessage, WriteTo As Writeable = Nil)
 Sub Post(URL As libcURL.URLParser, FormData As libcurl.MultipartForm, WriteTo As Writeable = Nil)
 Sub Post(URL As libcURL.URLParser, PostFields() As String, WriteTo As Writeable = Nil)

Parameters

Post(String, String(), Writeable)

Name Type Comment
URL String or URLParser The RFC 3986 URI to which the form should be posted. In libcurl 7.62.0 and newer, you may also pass an instance of URLParser.
PostFields String array An HTTP form which will be encoded as application/x-www-form-urlencoded.
WriteTo Writeable Optional. Downloaded data (if any) will be written to this object. If this parameter is Nil then use GetDownloadedData.

Post(String, MultipartForm, Writeable)

Name Type Comment
URL String or URLParser The RFC 3986 URI to which the form should be posted. In libcurl 7.62.0 and newer, you may also pass an instance of URLParser.
FormData MultipartForm An HTTP form which will be encoded as multipart/form-data. You may also pass a Dictionary to be converted.
WriteTo Writeable Optional. Downloaded data (if any) will be written to this object. If this parameter is Nil then use GetDownloadedData.

Post(String, MIMEMessage, Writeable)

Name Type Comment
URL String or URLParser The RFC 3986 URI to which the form should be posted. In libcurl 7.62.0 and newer, you may also pass an instance of URLParser.
FormData MIMEMessage An HTTP form which will be encoded as multipart/form-data.
WriteTo Writeable Optional. Downloaded data (if any) will be written to this object. If this parameter is Nil then use GetDownloadedData.

Return value

The synchronous versions of this method return True on success. Check cURLClient.LastError if this method returns False.

Remarks

POST an HTTP form using either multipart/form-data or application/x-www-form-urlencoded.

To encode the form using multipart/form-data, pass a Dictionary of NAME:VALUE pairs comprising HTTP form elements: NAME is a string containing the form-element name; VALUE may be a string or a FolderItem. You may also specify a MultipartForm instance for advanced options.

To encode the form using application/x-www-form-urlencoded, pass an array of URL-encoded NAME=VALUE strings comprising HTTP form elements.

If the URL parameter is empty ("") then the previous URL is reused; if there is no previous URL then the transfer will fail with error code CURLE_URL_MALFORMAT(3). If the previous transfer involved any sort of redirection then the "previous URL" is the URL enclosed in the final redirect.

Expect: 100-Continue

When using HTTP/1.1, libcURL will send a Expect: 100-Continue header and then wait briefly for the server to respond. This allows HTTP/1.1 servers to reject the operation before the (potentially large) form payload is transferred. Not all servers support this feature, and libcURL will continue normally if no intermediate reply comes from the server. You may disable this feature by deleting the Expect header.

POST non-form data

To POST other kinds of data use the Put() method and override the request method with "POST":

Dim curl As New cURLClient
curl.SetRequestMethod("POST")
curl.RequestHeaders.SetHeader("Content-Type", "text/plain") ' set the data type
If Not curl.Put("http://api.example.com", TheDataAsMemoryBlock) Then ' use the Put() method instead of Post()
  MsgBox("Error")
End If

See also

Clone this wiki locally