Repository navigation
POST and Upload
LibQurl provides two methods for sending data, each targeting a different use case:
| Method | Use case | Accepted sources |
|---|---|---|
SetPost() |
POST request body | String, Integer, Object, Array, Map, Buffer, File |
SetUpload() |
PUT-style upload, byte-range capable | File, |
Both are followed by Sync() or Async() to perform the transfer.
*Buffer support in SetUpload is planned but requires some extensions to the Storage class.
SetPost prepares the request body and sets the appropriate libcurl options. It accepts almost any source type and handles the encoding internally.
Note that you aren't limited to POST transfers. You're able to SetOpt a different http verb via CUSTOMREQUEST at any point after the SetPost.
curl.SetOpt("URL", "https://httpbin.org/post")
; Integer
curl.SetPost(1234567890)
curl.Sync()
; String
curl.SetPost("abcdefghij")
curl.Sync()
; Object (dumped as JSON)
data := { key: "value", count: 42 }
curl.SetPost(data)
curl.Sync()
; Array (dumped as JSON)
curl.SetPost(["item1", "item2"])
curl.Sync()
; Map (dumped as JSON)
curl.SetPost(Map("key", "value"))
curl.Sync()
; Buffer
buf := Buffer(17, 81)
curl.SetPost(buf)
curl.Sync()
; File
file := FileOpen("C:\path\to\upload.bin", "r")
curl.SetPost(file)
curl.Sync()String and Integer are sent as-is. Object, Array, and Map are dumped to JSON via cJson. File and Buffer are sent as binary.
SetPost returns the detected MIME type string. This is useful when the endpoint requires an explicit Content-Type:
mimeType := curl.SetPost(data)
curl.SetOpt("CONTENT_TYPE", mimeType)
curl.Sync()Object, Array, and Map sources always return "application/json". Other types are detected via libmagic.
SetUpload is for PUT-style uploads where you need byte-range control. It accepts File sources only.
As with SetPost, you aren't limited to PUT verbs for this transfer. You may call curl.SetOpt("CUSTOMREQUEST",<verb>) after invocation to change the request type, though it's on the user to understand if any verb changes are compatible with the remote server.
SetUpload(sourceData, startByte?, numBytes?, easy_handle?)-
startByte— offset into the source. Default 0. -
numBytes— number of bytes to send. Default is the full source size. - Both are clamped to valid bounds automatically.
easy_handle := curl.EasyInit()
curl.SetOpt("URL", "https://httpbin.org/put")
curl.SetOpt("CUSTOMREQUEST", "PUT")
file := FileOpen("C:\path\to\upload.bin", "r")
curl.SetUpload(file, 1024, 4096)
; send bytes 1024 through 5119 of the file
curl.WriteToFile("C:\path\to\response.json")
curl.Sync()
curl.EasyCleanup()When uploading, disable the automatic POST/UPLOAD state reset so the handle retains its upload configuration:
curl.autoResetToGET := 0autoResetToGET is currently a class-wide convention but will be made per-handle in the future.
See Terminology and Conventions for details.
ClearPost scrubs all POST and UPLOAD options from the handle and resets CUSTOMREQUEST to "GET". Use it when switching between upload and download on the same handle:
curl.SetPost("some data")
curl.Sync()
; Switch back to a plain GET on the same handle
curl.ClearPost()
curl.SetOpt("URL", "https://example.com")
curl.Sync()If autoResetToGET is enabled (default), this happens automatically after each transfer.
- MIME and Multipart — complex multipart form uploads
- Easy Handle Reference — full method list
Foundations
Operations
- Download Modes
- Setting and Listing Options
- Setting and Inspecting Headers
- POST and Upload
- Multiple Easy Handles
- Async and Multi Interface
- URL Construction
- Share Interface
- MIME and Multipart
- Raw Send and Receive
- Pause and Resume
- WebSocket
- SSL Sessions
- Debug and Diagnostics
API Reference
- Easy Handle Reference
- Multi Handle Reference
- Share Handle Reference
- MIME Handle Reference
- URL Handle Reference
- Utility Methods Reference
- WebSocket Reference
Code Snippets