### Install OpenSSL via MSYS2 Source: https://github.com/mercury13/curl4delphi/wiki/Home Command to install OpenSSL packages using the MSYS2 shell. ```bash pacboy sync mingw-w64-i686-openssl mingw-w64-x86_64-openssl ``` -------------------------------- ### CurlGet - Create a cURL Handle Source: https://context7.com/mercury13/curl4delphi/llms.txt The CurlGet function initializes a new cURL easy handle, returning an ICurl interface. This handle is the starting point for all subsequent cURL operations. ```APIDOC ## CurlGet - Create a cURL Handle ### Description Creates and returns a new `ICurl` interface instance that wraps a cURL easy handle. This is the entry point for all HTTP operations. ### Method Function ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```pascal uses Curl.Easy, Curl.Lib, Curl.Interfaces; var curl: ICurl; begin // Create a new cURL handle - automatically initialized curl := CurlGet; // The handle is ready to configure and use // Memory is automatically freed when the interface goes out of scope end; ``` ### Response #### Success Response - **curl** (ICurl) - An initialized cURL easy handle interface. #### Response Example (Interface instance, not a direct JSON/string example) ``` -------------------------------- ### Build GET URLs with Parameters using CurlGetBuilder Source: https://context7.com/mercury13/curl4delphi/llms.txt Creates a URL builder for constructing GET request URLs with properly encoded query parameters. Supports automatic URL encoding for spaces, special characters, and Unicode. ```Pascal uses Curl.Easy, Curl.Encoders, Curl.Interfaces; var curl: ICurl; builder: ICurlGetBuilder; begin // Build URL with query parameters (auto URL-encoded) builder := CurlGetBuilder('http://api.example.com/search'); builder.Param('q', 'delphi programming') // Spaces encoded as %20 .Param('category', 'books & magazines') // & encoded as %26 .Param('page', '1') .Param('lang', 'русский'); // Unicode supported curl := CurlGet; curl.SetUrl(builder) .SwitchRecvToString .Perform; // Result URL: http://api.example.com/search?q=delphi%20programming&category=books%20%26%20magazines&page=1&lang=%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9 Writeln('Search results: ', UTF8ToString(curl.ResponseBody)); end; ``` -------------------------------- ### Basic HTTP GET Request in Delphi Source: https://github.com/mercury13/curl4delphi/blob/master/readme.md Use this snippet for a basic HTTP GET request. Ensure you add Curl.Lib, Curl.Easy, and Curl.Interfaces to your project. The response body is stored as a string. ```delphi var curl : ICurl; curl := CurlGet; curl.SetUrl('http://example.com') .SetProxyFromIe .SetUserAgent(ChromeUserAgent) .SwitchRecvToString .Perform; Writeln(curl.ResponseBody); ``` -------------------------------- ### Create cURL Handle with CurlGet Source: https://context7.com/mercury13/curl4delphi/llms.txt Initializes a new cURL easy handle. This function must be called before any HTTP operations. Memory is managed automatically via reference counting. ```Pascal uses Curl.Easy, Curl.Lib, Curl.Interfaces; var curl: ICurl; begin // Create a new cURL handle - automatically initialized curl := CurlGet; // The handle is ready to configure and use // Memory is automatically freed when the interface goes out of scope end; ``` -------------------------------- ### Configure cURL Options with SetOpt Source: https://context7.com/mercury13/curl4delphi/llms.txt Utilize `SetOpt` for low-level cURL option configuration, offering type-safe overloads for various option types including integers, strings, enums, and 64-bit values. This provides direct access to cURL's extensive feature set. ```Pascal var curl: ICurl; begin curl := CurlGet; curl.SetUrl('http://example.com/api') // Integer options .SetOpt(CURLOPT_TIMEOUT, NativeUInt(30)) // 30 second timeout .SetOpt(CURLOPT_CONNECTTIMEOUT, NativeUInt(10)) // 10 second connect timeout .SetOpt(CURLOPT_MAXREDIRS, NativeUInt(5)) // Max 5 redirects .SetOpt(CURLOPT_POST, True) // Boolean option // String options .SetOpt(CURLOPT_COOKIE, 'session=abc123; user=john') .SetOpt(CURLOPT_REFERER, 'http://example.com/') // Enum options (type-safe) .SetOpt(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2) .SetOpt(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4) // 64-bit options .SetOpt(CURLOPT_INFILESIZE_LARGE, TCurlOff(1024 * 1024)) .SwitchRecvToString .Perform; end; ``` -------------------------------- ### Execute HTTP Request with Perform Source: https://context7.com/mercury13/curl4delphi/llms.txt Executes the configured HTTP request. Use a try-except block to catch `ECurlError` for standard error handling, or use `PerformNe` for non-throwing error handling that returns a `TCurlCode`. ```Pascal var curl: ICurl; code: TCurlCode; begin curl := CurlGet; curl.SetUrl('http://example.com'); // Standard approach - throws exception on error try curl.Perform; Writeln('Request successful'); except on E: ECurlError do Writeln('cURL error: ', E.Message, ' (code: ', Ord(E.Code), ')'); end; // Non-throwing approach - manual error handling code := curl.PerformNe; if code <> CURLE_OK then Writeln('Error: ', curl_easy_strerror(code)) else Writeln('Success!'); end; ``` -------------------------------- ### Instance Management Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Methods for duplicating curl instances. ```APIDOC ## Clone ### Description Creates an exact copy of the current ICurl instance, useful for multithreading. Note: Streams and string lists are shared by reference; manual management is recommended for thread safety. ``` -------------------------------- ### Set Custom HTTP Headers with CurlGetSList Source: https://context7.com/mercury13/curl4delphi/llms.txt Creates a linked list of custom HTTP headers to send with the request. Use Add for standard headers and AddRaw for pre-encoded strings. ```Pascal uses Curl.Easy, Curl.Slist, Curl.Lib, Curl.Interfaces; var curl: ICurl; headers: ICurlSList; begin headers := CurlGetSList; headers.Add('Authorization: Bearer eyJhbGciOiJIUzI1NiIs...') .Add('Content-Type: application/json') .Add('Accept: application/json') .AddRaw('X-API-Key: abc123'); // AddRaw for pre-encoded strings curl := CurlGet; curl.SetUrl('http://api.example.com/v1/users') .SetCustomHeaders(headers) .SwitchRecvToString .Perform; Writeln('API Response: ', UTF8ToString(curl.ResponseBody)); end; ``` -------------------------------- ### Use Simple String API Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Simplifies handling of small response bodies by using internal string buffers instead of manual stream management. ```Delphi function SwitchRecvToString : ICurl; function ResponseBody : RawByteString; ``` -------------------------------- ### Upload Memory Buffer as File with AddFileBuffer Source: https://context7.com/mercury13/curl4delphi/llms.txt Uploads data from a memory buffer as a file attachment without writing to disk. Supports both RawByteString and raw memory pointers. ```Pascal var curl: ICurl; form: ICurlForm; imageData: RawByteString; memBuffer: TMemoryStream; begin // Using RawByteString buffer imageData := LoadImageToRawBytes('source.png'); // Your function form := CurlGetForm; form.AddFileBuffer('photo', 'uploaded.png', 'image/png', imageData); curl := CurlGet; curl.SetUrl('http://example.com/api/images') .SetOpt(CURLOPT_POST, True) .SetForm(form) .SwitchRecvToString .Perform; // Using raw memory pointer memBuffer := TMemoryStream.Create; try memBuffer.LoadFromFile('document.pdf'); form := CurlGetForm; form.AddFileBuffer('file', 'document.pdf', 'application/pdf', memBuffer.Size, memBuffer.Memory^); curl := CurlGet; curl.SetUrl('http://example.com/upload') .SetOpt(CURLOPT_POST, True) .SetForm(form) .Perform; finally memBuffer.Free; end; end; ``` -------------------------------- ### ICurl Configuration and Execution Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Methods for configuring cURL options, setting streams, and managing request execution. ```APIDOC ## SetOpt ### Description Sets a cURL option using various data types. Note that string options are copied, while SList and HttpPost objects are referenced. ### Parameters - **aOption** (TCurlOption/TCurlIntOption/etc.) - Required - The cURL option to set. - **aData** (pointer/NativeUInt/boolean/PAnsiChar/etc.) - Required - The value to assign to the option. ## SetStream Methods ### Description Configures streams for receiving, sending, or header data. ### Parameters - **aData** (TStream) - Required - The stream object. - **aFlags** (TCurlStreamFlags) - Required - Flags such as csfAutoRewind or csfAutoDestroy. ## SwitchRecvToString ### Description Configures the receiver to use a string buffer instead of a stream for small response bodies. ## ResponseBody ### Description Retrieves the response content as a RawByteString if the receiver is configured as a string stream. ``` -------------------------------- ### Clone cURL Handle for Similar Requests Source: https://context7.com/mercury13/curl4delphi/llms.txt Use `Clone` to create an exact copy of a configured cURL handle. This is efficient for making multiple similar requests or for use in multithreaded scenarios. Note that streams are shared between clones and may need replacement. ```Pascal var baseRequest, request1, request2: ICurl; begin // Configure a base request with common settings baseRequest := CurlGet; baseRequest.SetUserAgent(ChromeUserAgent) .SetFollowLocation(True) .SetSslVerifyPeer(True) .SetCaFile('cacert.pem') .SwitchRecvToString; // Clone for first request request1 := baseRequest.Clone; request1.SetUrl('http://api.example.com/users') .Perform; Writeln('Users: ', request1.ResponseBody); // Clone for second request with same base settings request2 := baseRequest.Clone; request2.SetUrl('http://api.example.com/products') .Perform; Writeln('Products: ', request2.ResponseBody); // Note: Streams are shared between clones - replace if needed end; ``` -------------------------------- ### Enable HTTP Redirects with SetFollowLocation Source: https://context7.com/mercury13/curl4delphi/llms.txt Enables automatic following of HTTP redirects. Disabled by default. Use this when the target URL might change after the initial request. ```Pascal var curl: ICurl; effectiveUrl: PAnsiChar; begin curl := CurlGet; curl.SetUrl('http://ithappens.ru/') // Redirects to https://ithappens.me .SetFollowLocation(True) // Follow redirects automatically .SwitchRecvToString .Perform; // Get the final URL after all redirects effectiveUrl := curl.GetInfo(CURLINFO_EFFECTIVE_URL); Writeln('Final URL: ', effectiveUrl); Writeln('Response Code: ', curl.ResponseCode); end; ``` -------------------------------- ### Upload Files via Form with AddFile Source: https://context7.com/mercury13/curl4delphi/llms.txt Uploads disk files as part of a multipart form. Automatically handles Content-Type and can extract filenames. Supports Unicode paths. ```Pascal var curl: ICurl; form: ICurlForm; begin form := CurlGetForm; // Upload a single file with content type form.AddFile('document', 'C:\Users\John\report.pdf', 'application/pdf') .Add('description', 'Quarterly Report'); // Upload image with automatic filename extraction form.AddFile('photo', 'D:\Photos\vacation.jpg', 'image/jpeg'); curl := CurlGet; curl.SetUrl('http://example.com/upload') .SetOpt(CURLOPT_POST, True) .SetUserAgent(FirefoxUserAgent) .SetForm(form) .SwitchRecvToString .Perform; Writeln('Upload result: ', UTF8ToString(curl.ResponseBody)); end; ``` -------------------------------- ### Configure SSL Certificate Authority with SetCaFile Source: https://context7.com/mercury13/curl4delphi/llms.txt Sets the CA certificate file for SSL/TLS verification, essential for HTTPS requests with OpenSSL-based cURL builds. Includes options to disable verification, though not recommended for production. ```Pascal var curl: ICurl; begin curl := CurlGet; curl.SetUrl('https://secure.example.com/api') .SetCaFile('cacert.pem') // Path to CA certificate bundle .SetSslVerifyPeer(True) // Verify server certificate .SetSslVerifyHost(CURL_VERIFYHOST_MATCH) // Verify hostname matches cert .SetFollowLocation(True) .SwitchRecvToString .Perform; Writeln('Secure response: ', curl.ResponseBody); // Disable SSL verification (NOT recommended for production) curl := CurlGet; curl.SetUrl('https://self-signed.example.com') .SetSslVerifyPeer(False) .Perform; end; ``` -------------------------------- ### Set Common cURL Parameters Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Convenience methods for setting common parameters like URL, CA file, and SSL verification settings. ```Delphi function SetUrl(aData : PAnsiChar/RawByteString/UnicodeString) : ICurl; function SetCaFile(aData : PAnsiChar/RawByteString/UnicodeString) : ICurl; function SetUserAgent(aData : PAnsiChar/RawByteString/UnicodeString) : ICurl; function SetSslVerifyHost(aData : TCurlVerifyHost) : ICurl; function SetSslVerifyPeer(aData : boolean) : ICurl; ``` -------------------------------- ### Use Internet Explorer Proxy Settings with SetProxyFromIe Source: https://context7.com/mercury13/curl4delphi/llms.txt Automatically configures the cURL handle to use proxy settings from Internet Explorer/Windows system settings. Also shows manual proxy configuration. ```Pascal var curl: ICurl; begin curl := CurlGet; curl.SetUrl('http://example.com/api') .SetProxyFromIe // Auto-detect proxy from IE settings .SwitchRecvToString .Perform; Writeln(curl.ResponseBody); // Manual proxy configuration curl := CurlGet; curl.SetUrl('http://example.com') .SetOpt(CURLOPT_PROXY, 'http://proxy.company.com:8080') .SetOpt(CURLOPT_PROXYTYPE, CURLPROXY_HTTP) .Perform; end; ``` -------------------------------- ### Retrieve cURL Library Version and Capabilities Source: https://context7.com/mercury13/curl4delphi/llms.txt Call `curl_version_info` to obtain detailed information about the loaded cURL library, including its version, host, SSL and zlib versions, supported features (like SSL, IPv6, HTTP/2), and a list of supported protocols. ```Pascal var info: PCurlVersionInfo; protocols: PPAnsiChar; begin info := curl_version_info(CURLVERSION_NOW); Writeln('cURL version: ', info^.version); Writeln('Host: ', info^.host); Writeln('SSL version: ', info^.ssl_version); Writeln('zlib version: ', info^.libz_version); // Check features if (info^.features and CURL_VERSION_SSL) <> 0 then Writeln('SSL support: Yes'); if (info^.features and CURL_VERSION_IPV6) <> 0 then Writeln('IPv6 support: Yes'); if (info^.features and CURL_VERSION_HTTP2) <> 0 then Writeln('HTTP/2 support: Yes'); // List supported protocols Writeln('Supported protocols:'); protocols := info^.protocols; while protocols^ <> nil do begin Writeln(' - ', protocols^); Inc(protocols); end; end; ``` -------------------------------- ### Configure Request URL with SetUrl Source: https://context7.com/mercury13/curl4delphi/llms.txt Sets the target URL for an HTTP request. Supports various string types and automatically encodes Unicode strings to UTF-8. Can also build parameterized URLs using ICurlStringBuilder. ```Pascal var curl: ICurl; begin curl := CurlGet; // Using a simple string URL curl.SetUrl('http://example.com/api/data'); // Using Unicode URL (automatically UTF-8 encoded) curl.SetUrl('https://example.com/путь/файл'); // Using ICurlGetBuilder for parameterized URLs curl.SetUrl(CurlGetBuilder('http://example.com/search') .Param('q', 'search term') .Param('page', '1')); end; ``` -------------------------------- ### Set cURL Options Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Configures various cURL options using overloaded SetOpt methods. Note that some objects like SList and HttpPost are referenced and must persist until Perform completes. ```Delphi function SetOpt(aOption : TCurlOffOption; aData : TCurlOff) : ICurl; function SetOpt(aOption : TCurlOption; aData : pointer) : ICurl; function SetOpt(aOption : TCurlIntOption; aData : NativeUInt) : ICurl; function SetOpt(aOption : TCurlIntOption; aData : boolean) : ICurl; function SetOpt(aOption : TCurlStringOption; aData : PAnsiChar) : ICurl; function SetOpt(aOption : TCurlStringOption; aData : RawByteString) : ICurl; function SetOpt(aOption : TCurlStringOption; aData : UnicodeString) : ICurl; function SetOpt(aOption : TCurlProxyTypeOption; aData : TCurlProxyType) : ICurl; function SetOpt(aOption : TCurlUseSslOption; aData : TCurlUseSsl) : ICurl; function SetOpt(aOption : TCurlFtpMethodOption; aData : TCurlFtpMethod) : ICurl; function SetOpt(aOption : TCurlIpResolveOption; aData : TCurlIpResolve) : ICurl; function SetOpt(aOption : TCurlRtspSeqOption; aData : TCurlRtspSeq) : ICurl; function SetOpt(aOption : TCurlNetRcOption; aData : TCurlNetrc) : ICurl; function SetOpt(aOption : TCurlSslVersionOption; aData : TCurlSslVersion) : ICurl; function SetOpt(aOption : TCurlSlistOption; aData : PCurlSList) : ICurl; deprecated 'Use SetXXX instead: SetCustomHeaders, SetResolveList, etc.'; function SetOpt(aOption : TCurlPostOption; aData : PCurlHttpPost) : ICurl; deprecated 'Use SetForm or property Form instead.' ``` -------------------------------- ### Set Proxy from Internet Explorer Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Configures the HTTP proxy server settings based on the current Internet Explorer configuration. ```Delphi function SetProxyFromIe : ICurl; ``` -------------------------------- ### Set User-Agent Header with SetUserAgent Source: https://context7.com/mercury13/curl4delphi/llms.txt Sets the User-Agent header for HTTP requests. Predefined constants for common browsers are available, or a custom string can be used. ```Pascal var curl: ICurl; begin curl := CurlGet; curl.SetUrl('http://example.com/api') // Use predefined browser user agent .SetUserAgent(ChromeUserAgent) // Or FirefoxUserAgent, IeUserAgent, EdgeUserAgent, MozillaUserAgent .Perform; // Or set custom user agent curl := CurlGet; curl.SetUrl('http://example.com/api') .SetUserAgent('MyApp/1.0 (Delphi)') .Perform; end; ``` -------------------------------- ### SetFollowLocation - Enable HTTP Redirects Source: https://context7.com/mercury13/curl4delphi/llms.txt Enables automatic following of HTTP redirects (301, 302, etc.). ```APIDOC ## SetFollowLocation ### Description Enables automatic following of HTTP redirects (301, 302, etc.). Disabled by default to match cURL's behavior. ### Method N/A (Configuration Method) ### Parameters #### Request Body - **follow** (Boolean) - Required - Set to True to enable automatic redirect following. ``` -------------------------------- ### GetInfo Methods Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Methods for retrieving specific information about the curl request. ```APIDOC ## GetInfo ### Description Retrieves various types of information from the curl handle based on the provided info type. ### Parameters - **aCode/aInfo** (TCurlLongInfo/TCurlStringInfo/TCurlDoubleInfo/TCurlSListInfo/TCurlOffInfo/TCurlPtrInfo/TCurlSocketInfo) - Required - The specific info constant to retrieve. ## ResponseCode ### Description Returns the HTTP response code. Equivalent to calling GetInfo(CURLINFO_RESPONSE_CODE). ``` -------------------------------- ### Accessing Internet Explorer Proxy Settings Source: https://github.com/mercury13/curl4delphi/wiki/Raw-interface Utility function to retrieve the HTTP proxy configuration from Internet Explorer settings. ```Pascal ProxyFromIe ``` -------------------------------- ### Retrieve Transfer Information with GetInfo Source: https://context7.com/mercury13/curl4delphi/llms.txt Retrieves various information about a completed transfer, such as response codes, timing, URLs, and data sizes. Supports both integer and double types for different info constants. ```Pascal var curl: ICurl; httpCode: LongInt; downloadSize, uploadSize: TCurlOff; totalTime, connectTime: Double; effectiveUrl, contentType: PAnsiChar; begin curl := CurlGet; curl.SetUrl('http://example.com/largefile.dat') .SetFollowLocation(True) .Perform; // Long info httpCode := curl.GetInfo(CURLINFO_RESPONSE_CODE); // Or use the shortcut: httpCode := curl.ResponseCode; // 64-bit size info downloadSize := curl.GetInfo(CURLINFO_SIZE_DOWNLOAD_T); uploadSize := curl.GetInfo(CURLINFO_SIZE_UPLOAD_T); // Timing info (in seconds) totalTime := curl.GetInfo(CURLINFO_TOTAL_TIME); connectTime := curl.GetInfo(CURLINFO_CONNECT_TIME); // String info effectiveUrl := curl.GetInfo(CURLINFO_EFFECTIVE_URL); contentType := curl.GetInfo(CURLINFO_CONTENT_TYPE); Writeln('HTTP Code: ', httpCode); Writeln('Downloaded: ', downloadSize, ' bytes'); Writeln('Total time: ', totalTime:0:3, ' seconds'); Writeln('Final URL: ', effectiveUrl); Writeln('Content-Type: ', contentType); end; ``` -------------------------------- ### Submit Multipart Form Data with SetForm Source: https://context7.com/mercury13/curl4delphi/llms.txt Creates and submits multipart form data for POST requests. Supports simple text fields and file uploads. ```Pascal uses Curl.Easy, Curl.Form, Curl.Lib, Curl.Interfaces; var curl: ICurl; form: ICurlForm; begin // Simple form with text fields form := CurlGetForm; form.Add('username', 'john_doe') .Add('email', 'john@example.com') .Add('message', 'Hello World!'); // Unicode supported curl := CurlGet; curl.SetUrl('http://example.com/submit') .SetOpt(CURLOPT_POST, True) .SetForm(form) .SwitchRecvToString .Perform; Writeln('Response: ', curl.ResponseBody); end; ``` -------------------------------- ### Importing the curl4delphi unit Source: https://github.com/mercury13/curl4delphi/wiki/Raw-interface Include this unit in the uses clause to access libcurl functionality in Delphi. ```Pascal uses Curl.Lib; ``` -------------------------------- ### AddFile - Upload Files via Form Source: https://context7.com/mercury13/curl4delphi/llms.txt Uploads disk files as part of a multipart form. ```APIDOC ## AddFile ### Description Uploads disk files as part of a multipart form. Handles Unicode file paths and automatically sets Content-Type. ### Parameters #### Request Body - **name** (String) - Required - The field name for the file. - **path** (String) - Required - The local file path. - **contentType** (String) - Optional - The MIME type of the file. ``` -------------------------------- ### SetCaFile - Configure SSL Certificate Authority Source: https://context7.com/mercury13/curl4delphi/llms.txt Configures SSL/TLS verification settings, including CA certificate files and peer verification. ```APIDOC ## SetCaFile ### Description Sets the CA certificate file for SSL/TLS verification. Required for HTTPS requests when using OpenSSL-based cURL builds. ### Parameters #### Request Body - **caFile** (String) - Required - Path to the CA certificate bundle file. ``` -------------------------------- ### Advanced Form Field Builder with CurlGetField Source: https://context7.com/mercury13/curl4delphi/llms.txt Builds complex form fields using a fluent interface, supporting memory streams, custom content types, filenames, and custom headers. ```Pascal uses Curl.Easy, Curl.Form, Curl.Slist, Curl.Lib, Curl.Interfaces; var curl: ICurl; form: ICurlForm; pngStream: TMemoryStream; begin // Upload from memory stream pngStream := TMemoryStream.Create; // ... populate stream with image data ... form := CurlGetForm; form.Add(CurlGetField .Name('image') .FileStream(pngStream, [csfAutoRewind, csfAutoDestroy]) .ContentType('image/png') .FileName('generated.png')); // Field with custom headers form.Add(CurlGetField .Name('data') .Content('{"key": "value"}') .ContentType('application/json') .CustomHeaders(CurlGetSList .AddRaw('X-Custom-Header: value') .AddRaw('X-Another: data'))); curl := CurlGet; curl.SetUrl('http://example.com/api/upload') .SetOpt(CURLOPT_POST, True) .SetForm(form) .SwitchRecvToString .Perform; end; ``` -------------------------------- ### SetUrl - Configure Request URL Source: https://context7.com/mercury13/curl4delphi/llms.txt Configures the target URL for the HTTP request. Supports various string types and provides a builder for parameterized URLs. ```APIDOC ## SetUrl - Configure Request URL ### Description Sets the target URL for the HTTP request. Supports PAnsiChar, RawByteString, UnicodeString, and ICurlStringBuilder inputs with automatic UTF-8 encoding for Unicode strings. ### Method Interface Method (chained) ### Endpoint N/A (Method call on ICurl interface) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```pascal var curl: ICurl; begin curl := CurlGet; // Using a simple string URL curl.SetUrl('http://example.com/api/data'); // Using Unicode URL (automatically UTF-8 encoded) curl.SetUrl('https://example.com/путь/файл'); // Using ICurlGetBuilder for parameterized URLs curl.SetUrl(CurlGetBuilder('http://example.com/search') .Param('q', 'search term') .Param('page', '1')); end; ``` ### Response #### Success Response - **curl** (ICurl) - The same ICurl interface instance, allowing for method chaining. #### Response Example (Interface instance, not a direct JSON/string example) ``` -------------------------------- ### Perform - Execute HTTP Request Source: https://context7.com/mercury13/curl4delphi/llms.txt Executes the configured HTTP request. It can either raise an exception on failure or return a TCurlCode for manual error checking. ```APIDOC ## Perform - Execute HTTP Request ### Description Executes the configured HTTP request. Raises an `ECurlError` exception if the request fails. Use `PerformNe` for non-throwing error handling that returns a `TCurlCode` instead. ### Method Interface Method ### Endpoint N/A (Method call on ICurl interface) ### Parameters None ### Request Example ```pascal var curl: ICurl; code: TCurlCode; begin curl := CurlGet; curl.SetUrl('http://example.com'); // Standard approach - throws exception on error try curl.Perform; Writeln('Request successful'); except on E: ECurlError do Writeln('cURL error: ', E.Message, ' (code: ', Ord(E.Code), ')'); end; // Non-throwing approach - manual error handling code := curl.PerformNe; if code <> CURLE_OK then Writeln('Error: ', curl_easy_strerror(code)) else Writeln('Success!'); end; ``` ### Response #### Success Response (200) - **None** (Directly modifies the ICurl instance state or raises an exception). #### Response Example (No direct response body; success is indicated by lack of exception or `CURLE_OK` return code from `PerformNe`) ``` -------------------------------- ### Execution and Error Handling Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Methods for executing curl operations and managing error states. ```APIDOC ## Perform ### Description Performs the action. Internally calls RaiseIf(PerformNe). ## PerformNe ### Description Performs the action without throwing an exception. Returns a TCurlCode which the user must process manually. ## RaiseIf ### Description Checks a TCurlCode. If the code is not OK, it localizes the error message and throws an exception. ### Parameters - **aCode** (TCurlCode) - Required - The curl result code to evaluate. ``` -------------------------------- ### SwitchRecvToString - Capture Response Body as String Source: https://context7.com/mercury13/curl4delphi/llms.txt Configures the cURL handle to capture the response body into an internal string buffer, retrievable via `ResponseBody`. ```APIDOC ## SwitchRecvToString - Capture Response Body as String ### Description Configures the cURL handle to store the response body in an internal string buffer that can be retrieved with `ResponseBody`. Essential for capturing API responses. ### Method Interface Method (chained) ### Endpoint N/A (Method call on ICurl interface) ### Parameters None ### Request Example ```pascal var curl: ICurl; body: RawByteString; responseText: string; begin curl := CurlGet; curl.SetUrl('http://example.com/api/users') .SwitchRecvToString // Enable string response capture .Perform; // Get raw response bytes body := curl.ResponseBody; // Convert UTF-8 response to Delphi string responseText := UTF8ToString(body); Writeln(responseText); // Get HTTP status code Writeln('HTTP Status: ', curl.ResponseCode); end; ``` ### Response #### Success Response (200) - **ResponseBody** (RawByteString) - The raw bytes of the response body. - **ResponseCode** (Integer) - The HTTP status code of the response. #### Response Example ```json { "example": "RawByteString containing response data, e.g., \"{\"id\": 1, \"name\": \"test\"}\"" } ``` ``` -------------------------------- ### Set Custom Lists and Forms Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Configures complex data structures like custom headers or forms. These methods copy references to the provided objects. ```Delphi function SetForm(aForm : ICurlCustomForm) : ICurl; function SetCustomHeaders(v : ICurlCustomSList) : ICurl; function SetPostQuote(v : ICurlCustomSList) : ICurl; function SetTelnetOptions(v : ICurlCustomSList) : ICurl; function SetQuote(v : ICurlCustomSList) : ICurl; function SetPreQuote(v : ICurlCustomSList) : ICurl; function SetHttp200Aliases(v : ICurlCustomSList) : ICurl; function SetMailRcpt(v : ICurlCustomSList) : ICurl; function SetResolveList(v : ICurlCustomSList) : ICurl; function SetProxyHeader(v : ICurlCustomSList) : ICurl; function SetConnectTo(v : ICurlCustomSlist) : ICurl; ``` -------------------------------- ### SetUserAgent - Set User-Agent Header Source: https://context7.com/mercury13/curl4delphi/llms.txt Sets the User-Agent header for the HTTP request using predefined constants or custom strings. ```APIDOC ## SetUserAgent ### Description Sets the User-Agent header for the HTTP request. The library provides predefined constants for common browsers. ### Parameters #### Request Body - **userAgent** (String) - Required - The User-Agent string or predefined constant (e.g., ChromeUserAgent, FirefoxUserAgent). ``` -------------------------------- ### URL Encode Strings with CurlUrlEncode Functions Source: https://context7.com/mercury13/curl4delphi/llms.txt Use standalone functions like `CurlUrlEncodeFull`, `CurlUrlEncodeParam`, and `CurlUrlEncodeCustom` for URL-encoding strings. These functions support different strictness levels and custom character sets, including Unicode. ```Pascal uses Curl.Encoders; var encoded: RawByteString; begin // Full encoding - only alphanumeric and -_.~ allowed encoded := CurlUrlEncodeFull('Hello World! @#$%'); // Result: Hello%20World%21%20%40%23%24%25 // Parameter encoding - allows more characters for readability encoded := CurlUrlEncodeParam('user@example.com'); // Result: user@example.com (@ allowed in param encoding) // Unicode string support encoded := CurlUrlEncodeFull('Привет мир'); // Result: %D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%BC%D0%B8%D1%80 // Custom character sets encoded := CurlUrlEncodeCustom('test/path', ['a'..'z', '/']); // Result: test/path (/ preserved) end; ``` -------------------------------- ### Capture Response Body as String Source: https://context7.com/mercury13/curl4delphi/llms.txt Configures the cURL handle to capture the response body into an internal string buffer. Use `ResponseBody` to retrieve the raw bytes and `UTF8ToString` to convert to a Delphi string. Also retrieves the HTTP status code. ```Pascal var curl: ICurl; body: RawByteString; responseText: string; begin curl := CurlGet; curl.SetUrl('http://example.com/api/users') .SwitchRecvToString // Enable string response capture .Perform; // Get raw response bytes body := curl.ResponseBody; // Convert UTF-8 response to Delphi string responseText := UTF8ToString(body); Writeln(responseText); // Get HTTP status code Writeln('HTTP Status: ', curl.ResponseCode); end; ``` -------------------------------- ### CurlGetForm / SetForm - Multipart Form POST Source: https://context7.com/mercury13/curl4delphi/llms.txt Creates and submits multipart form data for POST requests. ```APIDOC ## SetForm ### Description Creates and submits multipart form data for POST requests. Supports simple fields, file uploads, and custom field configurations. ### Parameters #### Request Body - **form** (ICurlForm) - Required - The form object containing fields and files to be submitted. ``` -------------------------------- ### CurlGetField - Advanced Form Field Builder Source: https://context7.com/mercury13/curl4delphi/llms.txt Creates complex form fields with custom options including file streams, memory buffers, and custom headers. ```APIDOC ## CurlGetField ### Description Creates complex form fields with custom options including file streams, memory buffers, and custom headers using a fluent interface. ### Parameters #### Request Body - **name** (String) - Required - The field name. - **content** (String/Stream) - Required - The content to be sent in the field. ``` -------------------------------- ### Set Data Streams Source: https://github.com/mercury13/curl4delphi/wiki/ICurl Configures streams for receiving, sending, or header data. SetSendStream and SetForm are mutually exclusive. ```Delphi procedure SetRecvStream(aData : TStream; aFlags : TCurlStreamFlags); procedure SetSendStream(aData : TStream; aFlags : TCurlStreamFlags); procedure SetHeaderStream(aData : TStream; aFlags : TCurlStreamFlags); ``` -------------------------------- ### Stream Response to TStream Source: https://context7.com/mercury13/curl4delphi/llms.txt Directs the response body to a `TStream` object for efficient handling of large downloads. Options include automatic stream destruction and rewinding. Can be used for saving to files or memory streams. ```Pascal var curl: ICurl; fs: TFileStream; ms: TMemoryStream; begin // Download directly to file fs := TFileStream.Create('download.html', fmCreate); curl := CurlGet; curl.SetUrl('http://example.com/largefile.zip') .SetFollowLocation(True) .SetRecvStream(fs, [csfAutoDestroy]) // Auto-destroy stream when done .Perform; // fs is automatically freed // Download to memory stream ms := TMemoryStream.Create; curl := CurlGet; curl.SetUrl('http://example.com/data.json') .SetRecvStream(ms, [csfAutoRewind, csfAutoDestroy]) .Perform; Writeln('Downloaded ', ms.Size, ' bytes'); end; ``` -------------------------------- ### SetRecvStream - Stream Response to File or TStream Source: https://context7.com/mercury13/curl4delphi/llms.txt Directs the response body to a specified TStream object, suitable for handling large downloads efficiently. ```APIDOC ## SetRecvStream - Stream Response to File or TStream ### Description Directs the response body to a Delphi TStream object for efficient handling of large downloads. Supports automatic stream rewinding and destruction via flags. ### Method Interface Method (chained) ### Endpoint N/A (Method call on ICurl interface) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```pascal var curl: ICurl; fs: TFileStream; ms: TMemoryStream; begin // Download directly to file fs := TFileStream.Create('download.html', fmCreate); curl := CurlGet; curl.SetUrl('http://example.com/largefile.zip') .SetFollowLocation(True) .SetRecvStream(fs, [csfAutoDestroy]) // Auto-destroy stream when done .Perform; // fs is automatically freed // Download to memory stream ms := TMemoryStream.Create; curl := CurlGet; curl.SetUrl('http://example.com/data.json') .SetRecvStream(ms, [csfAutoRewind, csfAutoDestroy]) .Perform; Writeln('Downloaded ', ms.Size, ' bytes'); end; ``` ### Response #### Success Response (200) - **None** (Response data is written to the provided TStream). #### Response Example (No direct response body; data is streamed to the specified TStream) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.