### HTTP GET Request Example Source: https://everything.curl.dev/print.html Demonstrates a basic HTTP GET request to fetch a resource. The request includes a Host header and a User-agent. ```http GET / HTTP/1.1 User-agent: curl/2000 Host: example.com ``` -------------------------------- ### Install libcurl development package with apt Source: https://everything.curl.dev/print.html Install the development package for libcurl to get include headers and documentation for building applications. Choose the TLS backend you prefer. ```bash apt install libcurl4-openssl-dev ``` ```bash apt install libcurl4-gnutls-dev ``` -------------------------------- ### Build and Install Curl Source: https://everything.curl.dev/print.html Commands to build and install Curl after configuration. ```bash make make install ``` -------------------------------- ### Install libcurl using vcpkg Source: https://everything.curl.dev/install/windows/win-vcpkg.html Use this command to install the libcurl package for the x64 Windows architecture via vcpkg. Ensure vcpkg is installed and in your PATH. ```bash vcpkg.exe install curl:x64-windows ``` -------------------------------- ### Start FTP Download from Byte Offset Source: https://everything.curl.dev/usingcurl/downloads/resume.html Use this to initiate an FTP download starting from a specific byte offset. This is useful for resuming or controlling the download start point. ```bash curl --continue-at 100 ftp://example.com/bigfile ``` -------------------------------- ### Request First 200 Bytes Source: https://everything.curl.dev/http/modify/ranges.html Use the -r option with a start and end offset to get a specific range. This example requests bytes from 0 to 199. ```bash curl -r 0-199 http://example.com ``` -------------------------------- ### HTTP GET Response Example Source: https://everything.curl.dev/print.html Shows a typical HTTP response to a GET request, including status code, headers, and body. The response indicates success with a 200 OK status. ```http HTTP/1.1 200 OK Server: example-server/1.1 Content-Length: 5 Content-Type: plain/text hello ``` -------------------------------- ### Example: Repeat 'hello' 100 Times Source: https://everything.curl.dev/print.html This example demonstrates how to insert the string 'hello' repeated 100 times using the %repeat directive. ```bash %repeat[100 x hello]% ``` -------------------------------- ### Example libcurl C code generation Source: https://everything.curl.dev/print.html This C code is generated by the curl --libcurl option. It demonstrates basic libcurl setup, including initializing a handle, setting URL and other options, performing the transfer, and cleaning up. ```c /********* Sample code generated by the curl command-line tool ********** * All curl_easy_setopt() options are documented at: * https://curl.se/libcurl/c/curl_easy_setopt.html ************************************************************************/ #include int main(int argc, char *argv[]) { CURLcode ret; CURL *hnd; hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_URL, "http://example.com"); curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.45.0"); curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, "/home/daniel/.ssh/known_hosts"); curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); /* Here is a list of options the curl code used that cannot get generated as source easily. You may select to either not use them or implement them yourself. CURLOPT_WRITEDATA set to a objectpointer CURLOPT_WRITEFUNCTION set to a functionpointer CURLOPT_READDATA set to a objectpointer CURLOPT_READFUNCTION set to a functionpointer CURLOPT_SEEKDATA set to a objectpointer CURLOPT_SEEKFUNCTION set to a functionpointer CURLOPT_ERRORBUFFER set to a objectpointer CURLOPT_STDERR set to a objectpointer CURLOPT_HEADERFUNCTION set to a functionpointer CURLOPT_HEADERDATA set to a objectpointer */ ret = curl_easy_perform(hnd); curl_easy_cleanup(hnd); hnd = NULL; return (int)ret; } /**** End of sample code ****/ ``` -------------------------------- ### Install curl on Void Linux Source: https://everything.curl.dev/install/linux.html Use xbps-install to install the curl command-line utility on Void Linux. ```bash xbps-install curl ``` -------------------------------- ### Install libcurl development package on Void Linux Source: https://everything.curl.dev/install/linux.html Install the libcurl development package on Void Linux using xbps-install. ```bash xbps-install libcurl-devel ``` -------------------------------- ### Install curl on NixOS/Linux Source: https://everything.curl.dev/install/linux.html Install the curl command-line tool using nix-env on NixOS or other Linux distributions where Nix is installed. ```bash nix-env -i curl ``` -------------------------------- ### Install curl on Debian/Ubuntu Source: https://everything.curl.dev/install/linux.html Use apt to install the curl command-line tool. This also installs necessary dependencies, including libcurl. ```bash apt install curl ``` -------------------------------- ### Example libcurl C Code Generation Source: https://everything.curl.dev/libcurl/--libcurl.html This C code is generated by the --libcurl option and demonstrates how to perform a simple HTTP GET request using libcurl. It includes common options like setting the URL, user agent, and handling redirects. Note that some options, like CURLOPT_WRITEDATA, require custom function pointers and are listed as comments. ```c /********* Sample code generated by the curl command-line tool ********** * All curl_easy_setopt() options are documented at: * https://curl.se/libcurl/c/curl_easy_setopt.html ************************************************************************/ #include int main(int argc, char *argv[]) { CURLcode ret; CURL *hnd; hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_URL, "http://example.com"); curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.45.0"); curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, "/home/daniel/.ssh/known_hosts"); curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); /* Here is a list of options the curl code used that cannot get generated as source easily. You may select to either not use them or implement them yourself. CURLOPT_WRITEDATA set to a objectpointer CURLOPT_WRITEFUNCTION set to a functionpointer CURLOPT_READDATA set to a objectpointer CURLOPT_READFUNCTION set to a functionpointer CURLOPT_SEEKDATA set to a objectpointer CURLOPT_SEEKFUNCTION set to a functionpointer CURLOPT_ERRORBUFFER set to a objectpointer CURLOPT_STDERR set to a objectpointer CURLOPT_HEADERFUNCTION set to a functionpointer CURLOPT_HEADERDATA set to a objectpointer */ ret = curl_easy_perform(hnd); curl_easy_cleanup(hnd); hnd = NULL; return (int)ret; } /**** End of sample code ****/ ``` -------------------------------- ### Install libcurl development package on Silverblue/Kinoite/etc. Source: https://everything.curl.dev/install/linux.html Use rpm-ostree to install the libcurl development package on immutable Linux distributions. A system restart is required after installation. ```bash rpm-ostree install libcurl-devel ``` -------------------------------- ### Install libcurl development package on SUSE/openSUSE Source: https://everything.curl.dev/install/linux.html Install the libcurl development package on SUSE Linux and openSUSE Linux using zypper. ```bash zypper install libcurl-devel ``` -------------------------------- ### Install curl on SUSE/openSUSE Source: https://everything.curl.dev/install/linux.html Use zypper to install the curl command-line utility on SUSE Linux and openSUSE Linux. ```bash zypper install curl ``` -------------------------------- ### Install libcurl development package on Fedora Source: https://everything.curl.dev/install/linux.html Install the libcurl development package on Fedora-based distributions using dnf. ```bash dnf install libcurl-devel ``` -------------------------------- ### Install curl on Gentoo Source: https://everything.curl.dev/install/linux.html Use emerge to install the curl package, which includes the tool, libcurl, headers, and pkg-config files. ```bash emerge net-misc/curl ``` -------------------------------- ### Install curl with emerge Source: https://everything.curl.dev/print.html This command installs the curl tool, libcurl, headers, and pkg-config files on systems using the emerge package manager, such as Gentoo. ```bash emerge net-misc/curl ``` -------------------------------- ### HTTP POST Request Example Source: https://everything.curl.dev/print.html Illustrates an HTTP POST request with a small request body. This example includes Content-Length to specify the body size. ```http POST / HTTP/1.1 Host: example.com User-agent: curl/2000 Content-Length: 5 hello ``` -------------------------------- ### Install curl on Silverblue/Kinoite/etc. Source: https://everything.curl.dev/install/linux.html Use rpm-ostree to install the curl command-line tool on immutable Linux distributions like Silverblue, Kinoite, Sericea, and Onyx. A system restart is required after installation. ```bash rpm-ostree install curl ``` -------------------------------- ### Install libcurl development package on Debian/Ubuntu (OpenSSL) Source: https://everything.curl.dev/install/linux.html Install the libcurl development package with OpenSSL backend for building applications against libcurl. ```bash apt install libcurl4-openssl-dev ``` -------------------------------- ### Install curl on Fedora Source: https://everything.curl.dev/install/linux.html Use dnf to install the curl command-line tool on Fedora Workstation and other Fedora-based distributions. ```bash dnf install curl ``` -------------------------------- ### Example URL Breakdown Source: https://everything.curl.dev/print.html An example URL showing how different parts are used in an HTTP request. It details the scheme, hostname, and path. ```url https://www.example.com/path/to/file ``` -------------------------------- ### Enable SSL False Start Source: https://everything.curl.dev/transfers/options/tls.html Enable SSL False Start with `CURLOPT_SSL_FALSESTART`. This option, along with others like `CURLOPT_SSL_CIPHER_LIST`, allows for fine-tuning TLS connection behavior. ```c curl_easy_setopt(curl, CURLOPT_SSL_FALSESTART, 1); ``` -------------------------------- ### Install Local Curl Package File Source: https://everything.curl.dev/print.html Installs a locally built curl package file using the pacman -U command. This is used after compiling a custom version of curl. ```bash pacman -U mingw-w64-x86_64-curl-winssl-7.80.0-1-any.pkg.tar.zst ``` -------------------------------- ### Setup Connection with Protocol Handler Source: https://everything.curl.dev/internals/handler.html Calls the protocol-specific setup_connection function if it is defined in the handler. ```c if(conn->handler->setup_connection) result = conn->handler->setup_connection(data, conn); ``` -------------------------------- ### Setting and Redirecting URLs Source: https://everything.curl.dev/print.html Demonstrates how to set an initial URL and then update it with a relative URL, causing the handle to adapt to the new path. ```c CURLU *h = curl_url(); rc = curl_url_set(h, CURLUPART_URL, "https://example.com/foo/bar?name=moo", 0); rc = curl_url_set(h, CURLUPART_URL, "../test?another", 0); ``` -------------------------------- ### Extracting Local Port Number Source: https://everything.curl.dev/print.html This example shows how to get the local port number used for the connection of a completed transfer using `CURLINFO_LOCAL_PORT`. ```APIDOC ## Get Local Port Number ### Description Retrieves the local port number used for the connection of the previous transfer. ### Method `curl_easy_getinfo()` ### Parameters #### Input - **curl**: An initialized libcurl easy handle. - **info_type**: `CURLINFO_LOCAL_PORT` to request the local port number. - **return_pointer**: A pointer to a `long` variable to store the port number. ### Return Value - **CURLcode**: Indicates success or failure of the operation. ### Example ```c CURLcode res; long port_number; res = curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port_number); ``` ``` -------------------------------- ### Example URL Structure Source: https://everything.curl.dev/print.html Illustrates the components of a sample URL and how they map to CURLUPART constants. ```text http://joe:7Hbz@example.com:8080/images?id=5445#footer ``` -------------------------------- ### Get libcurl Easy Option by ID Source: https://everything.curl.dev/print.html Use `curl_easy_option_by_id()` to find a `struct curl_easyoption` pointer given the option's ID. This example retrieves the name for `CURLOPT_VERBOSE`. ```c const struct curl_easyoption *opt = curl_easy_option_by_id(CURLOPT_VERBOSE); if(opt) { printf("This option has the name: %s\n", opt->name); } ``` -------------------------------- ### Function Invocation with Open Parenthesis Source: https://everything.curl.dev/print.html When a function invocation starts a block, ensure proper indentation for subsequent lines within the block. This example shows a function call within an if statement. ```c if(option) { result = parse_login_details(option, strlen(option), (userp ? &user : NULL), (passwdp ? &passwd : NULL), NULL); } ``` -------------------------------- ### Create URL by Setting Components Source: https://everything.curl.dev/cmdline/urls/trurl.html Construct a URL by specifying components like host and scheme using the --set option. ```bash $ trurl --set host=example.com --set scheme=ftp ftp://example.com/ ``` -------------------------------- ### Get Byte Range from File Content Source: https://everything.curl.dev/cmdline/variables/assign.html Starting from curl 8.12.0, specify a byte range [N-M] to extract a portion of the file content. The end offset M can be omitted to read until the end of the file. ```bash curl --variable "varName[100-199]@filename" ``` -------------------------------- ### Get libcurl Easy Option by Name Source: https://everything.curl.dev/print.html Use `curl_easy_option_by_name()` to find a `struct curl_easyoption` pointer given the option's name (without the `CURLOPT_` prefix). This example retrieves the ID for `CURLOPT_VERBOSE`. ```c const struct curl_easyoption *opt = curl_easy_option_by_name("VERBOSE"); if(opt) { printf("This option wants CURLoption %x\n", (int)opt->id); } ``` -------------------------------- ### Valid file:// URL formats Source: https://everything.curl.dev/cmdline/urls/scheme.html Demonstrates the correct syntax for file:// URLs, including localhost, IP address, and a blank hostname. ```bash file://localhost/path/to/file file://127.0.0.1/path/to/file file:///path/to/file ``` -------------------------------- ### Multi-line Conditional Statement Formatting Source: https://everything.curl.dev/print.html Align continuation lines of conditional statements to improve readability. Operators should not start continuation lines. This example shows a complex condition spanning multiple lines. ```c if(Curl_pipeline_wanted(handle->multi, CURLPIPE_HTTP1) && (handle->set.httpversion != CURL_HTTP_VERSION_1_0) && (handle->set.httpreq == HTTPREQ_GET || handle->set.httpreq == HTTPREQ_HEAD)) /* did not ask for HTTP/1.0 and a GET or HEAD */ return TRUE; ``` -------------------------------- ### Standard .netrc Entry for Example.com Source: https://everything.curl.dev/usingcurl/netrc.html This is a standard entry in a .netrc file for 'example.com', specifying the username 'daniel' and password 'qwerty'. Ensure this file has restricted read permissions. ```shell machine example.com login daniel password qwerty ``` -------------------------------- ### Set curl Keepalive Probe Count Source: https://everything.curl.dev/usingcurl/connections/keepalive.html Starting from curl 8.9.0, you can control the number of unanswered keepalive probes before giving up using the --keepalive-cnt option. This example sets the count to 3. ```bash curl --keepalive-cnt 3 https://example.com ``` -------------------------------- ### Extract Byte Range from Variable Content (File) Source: https://everything.curl.dev/print.html Starting in curl 8.12.0, extract a byte range from a variable's content by appending `[N-M]` to the variable name. This example shows extracting from a file. ```bash curl --variable "varName[100-199]@filename" ``` -------------------------------- ### Initializing URL and Setting Full URL Source: https://everything.curl.dev/helpers/url/set-part.html Shows how to initialize a CURLU handle and set an initial full URL. This is the first step before modifying individual components. ```c const char *url="http://joe:7Hbz@example.com:8080/images?id=5445#footer"; CURLU *h = curl_url(); rc = curl_url_set(h, CURLUPART_URL, url, 0); ``` -------------------------------- ### Set up Build Environment with pacman Source: https://everything.curl.dev/install/windows/win-msys2.html Installs essential build tools and the MinGW-w64 toolchain required for compiling software on MSYS2. This includes syncing repositories, installing git and base development packages, and the GCC compiler for x86_64. ```bash # Sync the repositories pacman -Syu # Install git, autoconf, patch, etc pacman -S git base-devel # Install GCC for x86_64 pacman -S mingw-w64-x86_64-toolchain ``` -------------------------------- ### Limit to 8 Transfers Every 5 Seconds Source: https://everything.curl.dev/print.html Starting from curl 8.10.0, this example shows how to specify a number of time units. It limits curl to no more than eight transfers within any five-second interval. The `-O` option saves files with their original names. ```bash curl --rate 8/5s -O https://example.com/[1-100].jpg ``` -------------------------------- ### WebSocket Communication Example in C Source: https://everything.curl.dev/print.html This C code sets up a WebSocket stream using libcurl, then performs communication using curl_ws_recv() and curl_ws_send(). It includes functions for sending PING frames, receiving PONG frames, and closing the connection. Ensure libcurl is properly installed and linked. ```c #include #ifdef _WIN32 #include #include #define sleep(s) Sleep((DWORD)(s * 1000)) #else #include #endif #include static CURLcode ping(CURL *curl, const char *send_payload) { CURLcode result = CURLE_OK; const char *buf = send_payload; size_t sent, blen = strlen(send_payload); while(blen) { result = curl_ws_send(curl, buf, blen, &sent, 0, CURLWS_PING); if(result == CURLE_OK) { buf += sent; /* deduct what was sent */ blen -= sent; } else if(result == CURLE_AGAIN) { /* blocked on sending */ fprintf(stderr, "ws: sent PING blocked, waiting a second\n"); sleep(1); /* either select() on socket or max timeout would be good here. */ } else /* real error sending */ break; } if(result == CURLE_OK) fprintf(stderr, "ws: sent PING with payload\n"); return result; } static CURLcode recv_pong(CURL *curl, const char *expected_payload) { size_t rlen = 0; const struct curl_ws_frame *meta; char buffer[256]; CURLcode result; retry: result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta); if(result == CURLE_OK) { /* on small PING content, this example assumes the complete * PONG content arrives in one go. Larger frames arrive * in chunks, however. */ if(meta->flags & CURLWS_PONG) { int same = 0; if(rlen == strlen(expected_payload)) { if(!memcmp(expected_payload, buffer, rlen)) same = 1; } fprintf(stderr, "ws: received PONG with %s payload back\n", same ? "same" : "different"); } else if(meta->flags & CURLWS_TEXT) { fprintf(stderr, "ws: received TEXT frame '%.*s'\n", (int)rlen, buffer); } else if(meta->flags & CURLWS_BINARY) { fprintf(stderr, "ws: received BINARY frame of %u bytes\n", (unsigned int)rlen); } else { /* some other frame arrived. */ fprintf(stderr, "ws: received frame of %u bytes rflags %x\n", (unsigned int)rlen, meta->flags); goto retry; } } else if(result == CURLE_AGAIN) { /* blocked on receiving */ fprintf(stderr, "ws: PONG not there yet, waiting a second\n"); sleep(1); /* either select() on socket or max timeout would be good here. */ goto retry; } if(result != CURLE_OK) fprintf(stderr, "ws: curl_ws_recv returned %u, received %u\n", (unsigned int)result, (unsigned int)rlen); return result; } /* close the connection */ static void websocket_close(CURL *curl) { size_t sent; (void)curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE); } static CURLcode websocket(CURL *curl) { CURLcode result; int i = 0; do { result = ping(curl, "foobar"); if(result != CURLE_OK) break; result = recv_pong(curl, "foobar"); if(result != CURLE_OK) break; sleep(1); } while(i++ < 10); websocket_close(curl); return result; } int main(int argc, const char *argv[]) { CURL *curl; CURLcode result = curl_global_init(CURL_GLOBAL_ALL); if(result != CURLE_OK) return (int)result; curl = curl_easy_init(); if(curl) { if(argc == 2) curl_easy_setopt(curl, CURLOPT_URL, argv[1]); else curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com"); curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* Perform the request, result gets the return code */ result = curl_easy_perform(curl); /* Check for errors */ if(result != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); else { /* connected and ready */ result = websocket(curl); } /* always cleanup */ curl_easy_cleanup(curl); } curl_global_cleanup(); return (int)result; } ``` -------------------------------- ### Example: Read, Trim, and URL-Encode File Content Source: https://everything.curl.dev/print.html Demonstrates reading a file's content into a variable, trimming whitespace, URL-encoding it, and sending it as POST data. Assumes a default HOME path. ```bash __ curl \ --variable %HOME=/home/default \ --expand-variable fix@{{HOME}}/.secret \ --expand-data "{{fix:trim:url}}" \ --url https://example.com/ ``` -------------------------------- ### Install curl with Homebrew Source: https://everything.curl.dev/install/macos.html Use Homebrew to install the latest curl package. This command installs curl and its dependencies. ```bash brew install curl ``` -------------------------------- ### Create BoringsSL Lib and Include Directories Source: https://everything.curl.dev/print.html Instructions to create a 'lib' directory and symlink the built BoringSSL libraries into it, ensuring the 'include' directory is present. ```bash $ mkdir lib $ cd lib $ ln -s ../build/ssl/libssl.a $ ln -s ../build/crypto/libcrypto.a ``` -------------------------------- ### Example Curl Version Output (Windows 10) Source: https://everything.curl.dev/cmdline/curlver.html This is an example of the output from `curl --version` on a Windows 10 machine. Note the differences in build components and release date compared to Linux builds. ```text curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL Release-Date: [unreleased] Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL ``` -------------------------------- ### Basic GET Request with Curl Source: https://everything.curl.dev/print.html This is a standard GET request to a specified URL. Curl automatically sets the method to GET. ```bash curl http://example.com/file ``` -------------------------------- ### Connect using explicit TLS (STARTTLS) Source: https://everything.curl.dev/usingcurl/pop3.html This command initiates a connection and then upgrades it to TLS using STARTTLS, requiring the upgrade to succeed. ```bash curl pop3://mail.example.com/ --ssl-reqd ``` -------------------------------- ### Install curl on Arch Linux Source: https://everything.curl.dev/install/linux.html Use pacman to install the curl command-line tool on Arch Linux. It is typically installed by default. ```bash pacman -S curl ``` -------------------------------- ### Basic HTTP GET Request Source: https://everything.curl.dev/protocols/http.html Demonstrates a simple GET request to fetch a resource. GET requests typically do not include a request body. ```http GET / HTTP/1.1 User-agent: curl/2000 Host: example.com ``` -------------------------------- ### Multipart Form-Post with Multi Interface Source: https://everything.curl.dev/print.html This example demonstrates how to make a multipart form-post using the curl multi interface. It includes setting up form fields, headers, and handling the multi-perform loop. ```c #include #include #include #include int main(void) { CURL *curl; CURLM *multi_handle; int still_running = 0; curl_mime *form = NULL; curl_mimepart *field = NULL; struct curl_slist *headerlist = NULL; static const char buf[] = "Expect:"; curl = curl_easy_init(); multi_handle = curl_multi_init(); if(curl && multi_handle) { /* Create the form */ form = curl_mime_init(curl); /* Fill in the file upload field */ field = curl_mime_addpart(form); curl_mime_name(field, "sendfile"); curl_mime_filedata(field, "multi-post.c"); /* Fill in the filename field */ field = curl_mime_addpart(form); curl_mime_name(field, "filename"); curl_mime_data(field, "multi-post.c", CURL_ZERO_TERMINATED); /* Fill in the submit field too, even if this is rarely needed */ field = curl_mime_addpart(form); curl_mime_name(field, "submit"); curl_mime_data(field, "send", CURL_ZERO_TERMINATED); /* initialize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, buf); /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/upload.cgi"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_MIMEPOST, form); curl_multi_add_handle(multi_handle, curl); do { CURLMcode mc = curl_multi_perform(multi_handle, &still_running); if(still_running) /* wait for activity, timeout or "nothing" */ mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL); if(mc) break; } while(still_running); curl_multi_cleanup(multi_handle); /* always cleanup */ curl_easy_cleanup(curl); /* then cleanup the form */ curl_mime_free(form); /* free slist */ curl_slist_free_all(headerlist); } return 0; } ``` -------------------------------- ### Example URL with Fragment Source: https://everything.curl.dev/cmdline/urls/fragment.html A standard URL demonstrating the fragment part, indicated by a hash symbol. ```text https://www.example.com/info.html#the-plot ``` -------------------------------- ### Set Up MSYS2 Build Environment Source: https://everything.curl.dev/print.html Installs essential build tools and the GCC toolchain for x86_64 architecture within MSYS2. This prepares the environment for compiling packages. ```bash # Sync the repositories pacman -Syu # Install git, autoconf, patch, etc pacman -S git base-devel # Install GCC for x86_64 pacman -S mingw-w64-x86_64-toolchain ``` -------------------------------- ### Single-Line .netrc Entry for Example.com Source: https://everything.curl.dev/usingcurl/netrc.html This demonstrates an alternative single-line format for the .netrc file, achieving the same result as the multi-line entry for 'example.com' with user 'daniel' and password 'qwerty'. ```shell machine example.com login daniel password qwerty ``` -------------------------------- ### Append Data to URL as Query Parameters with GET Source: https://everything.curl.dev/print.html Use the -G option to append URL-encoded data to the specified URL and perform a GET request. This is useful for switching between POST and GET methods. ```bash curl -G --data-urlencode "name=daniel stenberg" https://example.com/ ``` -------------------------------- ### Fetch HTML from URL with libcurl Source: https://everything.curl.dev/examples/get.html This is a fundamental libcurl program. It initializes libcurl, sets the target URL, performs the request, and checks for errors. The output is sent to stdout by default. For most applications, you'll want to install a write callback to handle the received data. ```c #include #include int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); /* Perform the request, 'res' holds the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); } return 0; } ``` -------------------------------- ### HTML Form Example Source: https://everything.curl.dev/http/post/multipart.html An example of an HTML form that uses multipart/form-data encoding for submission. ```html
Name:
File:
``` -------------------------------- ### Install Local Package File with pacman Source: https://everything.curl.dev/install/windows/win-msys2.html Installs a locally built cURL package file using pacman. This command is used after compiling a custom version of cURL, allowing you to install the generated .pkg.tar.zst file. ```bash pacman -U mingw-w64-x86_64-curl-winssl-7.80.0-1-any.pkg.tar.zst ``` -------------------------------- ### Default GET Request Line Source: https://everything.curl.dev/print.html The initial request line for a basic GET request as generated by curl. ```http GET /file HTTP/1.1 ```