curl_easy_setopt

Syntax

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter); 

Parameters

handle Handle to a curl session.
option A constant representing the CURLoption value to be obtained.
parameter This parameter can be a long, a function pointer, an object pointer or a curl_off_t. For information on what parameter is required for a specific option, see the tables below.

Return Values

If the operation was successful, CURLE_OK is returned. Otherwise, a specific libcurl Error Code is returned. If attempting to set an option that libcurl is unaware of (perhaps the library is too old to support the option or the option was removed in a recent version), this function will return CURLE_FAILED_INIT.

Description

curl_easy_setopt is used to instruct libcurl how to behave. Change libcurl's behavior by using the appropriate options to curl_easy_setopt. All options are set with the option followed by a parameter. That parameter can be a long, a function pointer, an object pointer or a curl_off_t, depending on what the specific option expects. Incorrect input values may cause libcurl to behave unexpectedly. Only set one option in each function call. A typical application uses many curl_easy_setopt calls in the setup phase.

Options set with this function call are valid for all future transfers performed using this handle. The options are not reset between transfers, so if needing subsequent transfers with different options, change them between the transfers. Optionally, reset all options back to internal default with curl_easy_reset.

Strings passed to libcurl as char * arguments, are copied by the library; the string storage associated to the pointer argument may be overwritten after curl_easy_setopt returns. Exceptions to this rule are described in the option details below.

The handle is the return code from a curl_easy_init or curl_easy_duphandle call.

CURLoption Values

The CURLoption option has several types of values you can specify:

Behavior Options

CURLOPT_VERBOSE

Set the parameter to 1 to get the library to display a large amount of verbose information about its operations. Useful for libcurl and/or protocol debugging and understanding. The verbose information will be sent to stderr.

You hardly ever want this set in production use, you will almost always want this when you debug/report problems. Another neat option for debugging is the CURLOPT_DEBUGFUNCTION.

CURLOPT_HEADER

A parameter set to 1 instructs the library to include the header in the body output. This is only relevant for protocols that actually have headers preceding the data (like HTTP).

CURLOPT_NOPROGRESS

Pass a long. If set to 1, it instructs the library to shut off the progress meter completely. It will also present the CURLOPT_PROGRESSFUNCTION from getting called.

Callback Options

CURLOPT_WRITEFUNCTION

Function pointer that should match the following prototype: size_t function( char *ptr, size_t size, size_t nmemb, void *userdata); This function gets called by libcurl as soon as there is data received that needs to be saved. The size of the data pointed to by ptr is size multiplied with nmemb, it will not be zero-terminated. Return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it will signal an error to the library. This will abort the transfer and return CURLE_WRITE_ERROR.

The function can return CURL_WRITEFUNC_PAUSE which then will cause writing to this connection to become paused. For more information, see curl_easy_pause.

This function may be called with zero bytes data if the transferred file is empty.

Set the userdata argument with the CURLOPT_WRITEDATA option.

The callback function will be passed as much data as possible in all invokes, but you cannot possibly make any assumptions. It may be one byte, it may be thousands. The maximum amount of data that can be passed to the write callback is defined in the curl.h header file: CURL_MAX_WRITE_SIZE.

CURLOPT_WRITEDATA

Data pointer to pass to the file write function. If you use the CURLOPT_WRITEFUNCTION option, this is the pointer you will get as input.

The internal CURLOPT_WRITEFUNCTION will write the data to stdout.

This option is also known with the older name CURLOPT_FILE

CURLOPT_READFUNCTION

Function pointer that should match the following prototype: size_t function( void *ptr, size_t size, size_t nmemb, void *userdata); This function gets called by libcurl as soon as it needs to read data in to send it to the peer. The data area pointed at by the pointer ptr may be filled with at most size multiplied with nmemb number of bytes. Your function must return the actual number of bytes that you stored in that memory area. Returning 0 will signal end-of-file to the library and cause it to stop the current transfer.

If you stop the current transfer by returning 0 "prematurely" (i.e. before the server expected it, such as when indicating that you will upload 'N bytes' and you upload less than 'N bytes'), you may experience that the server "hangs" waiting for the rest of the data that will not come.

The read callback may return CURL_READFUNC_ABORT to stop the current operation immediately, resulting in a CURLE_ABORTED_BY_CALLBACK error code from the transfer.

The function can return CURL_READFUNC_PAUSE which then will cause reading from this connection to become paused. For more information, see curl_easy_pause.

CURLOPT_READDATA

Data pointer to pass to the file read function. If you use the CURLOPT_READFUNCTION option, this is the pointer you will get as input.

This option was also known by the older name CURLOPT_INFILE.

CURLOPT_IOCTLFUNCTION

Function pointer that should match the curl_ioctl_callback prototype found in <curl/curl.h>. This function gets called by libcurl when something specific and I/O-related needs to be performed that the library cannot perform by itself. For now, rewinding the read data stream is the only action it can request. The rewinding of the read data stream may be necessary when performing a HTTP PUT or POST with a multi-pass authentication method.

Use CURLOPT_SEEKFUNCTION instead to provide seeking!

CURLOPT_IOCTLDATA

Pass a pointer that will be untouched by libcurl and passed as the 3rd argument in the ioctl callback set with CURLOPT_IOCTLFUNCTION.

CURLOPT_SEEKFUNCTION

Function pointer that should match the following prototype: int function(void *instream, curl_off_t offset, int origin); This function gets called by libcurl to seek to a certain position in the input stream and can be used to fast forward a file in a resumed upload (instead of reading all uploaded bytes with the normal read function/callback). It is also called to rewind a stream when performing a HTTP PUT or POST with a multi-pass authentication method. The function shall work like "fseek" or "lseek" and accepted SEEK_SET, SEEK_CUR and SEEK_END as argument for origin, although libcurl only passes SEEK_SET. The callback must return 0 (CURL_SEEKFUNC_OK) on success, 1 (CURL_SEEKFUNC_FAIL) to cause the upload operation to fail or 2 (CURL_SEEKFUNC_CANTSEEK) to indicate that while the seek failed, libcurl is free to work around the problem if possible. The latter can occasionally be performed by instead reading from the input or similar.

If you forward the input arguments directly to "fseek" or "lseek", note that the data type for offset is not the same as defined for curl_off_t on many systems!

CURLOPT_SEEKDATA

Data pointer to pass to the file read function. If you use the CURLOPT_SEEKFUNCTION option, this is the pointer you will get as input. If you do not specify a seek callback, NULL is passed.

CURLOPT_SOCKOPTFUNCTION

Function pointer that should match the curl_sockopt_callback prototype found in <curl/curl.h>. This function gets called by libcurl after the socket call but before the connect call. The callback's purpose argument identifies the exact purpose for this particular socket. It passes the newly created socket descriptor so additional setsockopt calls can be performed at the user's discretion. Return 0 (zero) from the callback on success. Return 1 from the callback function to signal an unrecoverable error to the library and it will close the socket and return CURLE_COULDNT_CONNECT.

The callback function may return CURL_SOCKOPT_ALREADY_CONNECTED, which instructs libcurl that the socket is in fact already connected and then libcurl will not attempt to connect it.

CURLOPT_SOCKOPTDATA

Pass a pointer that will be untouched by libcurl and passed as the first argument in the sockopt callback set with CURLOPT_SOCKOPTFUNCTION.

CURLOPT_OPENSOCKETFUNCTION

Function pointer that should match the curl_opensocket_callback prototype found in <curl/curl.h>. This function gets called by libcurl instead of the socket(2) call. The callback's purpose argument identifies the exact purpose for this particular socket. It passes the resolved peer address as a address argument so the callback can modify the address or refuse to connect. The callback function should return the socket or CURL_SOCKET_BAD in case no connection should be established or any error detected. Any additional setsockopt(2) calls can be performed on the socket at the user's discretion. CURL_SOCKET_BAD return value from the callback function will signal an unrecoverable error to the library and it will return CURLE_COULDNT_CONNECT. This return code can be used for IP address blacklisting. The default behavior is:

  return socket(addr->family, addr->socktype, addr->protocol);

CURLOPT_OPENSOCKETDATA

Pass a pointer that will be untouched by libcurl and passed as the first argument in the opensocket callback set with CURLOPT_OPENSOCKETFUNCTION.

CURLOPT_CLOSESOCKETFUNCTION

Function pointer that should match the curl_closesocket_callback prototype found in <curl/curl.h>. This function gets called by libcurl instead of the close or closesocket call when sockets are closed (not for any other file descriptors). This is the reverse to the CURLOPT_OPENSOCKETFUNCTION option. Return 0 to signal success and 1 if there was an error.

CURLOPT_CLOSESOCKETDATA

Pass a pointer that will be untouched by libcurl and passed as the first argument in the opensocket callback set with CURLOPT_CLOSESOCKETFUNCTION.

CURLOPT_PROGRESSFUNCTION

Function pointer that should match the curl_progress_callback prototype found in <curl/curl.h>. This function gets called by libcurl instead of its internal equivalent with a frequent interval during operation (roughly once per second or sooner) no matter if data is being transferred or not. Unknown/unused argument values passed to the callback will be set to zero (like if you only download data, the upload size will remain 0). Returning a nonzero value from this callback will cause libcurl to abort the transfer and return CURLE_ABORTED_BY_CALLBACK.

If you transfer data with the multi interface, this function will not be called during periods of idleness unless you call the appropriate libcurl function that performs transfers.

CURLOPT_NOPROGRESS must be set to 0 to make this function actually get called.

NOTE:
Cafe libcurl only supports synchronous DNS lookup. Progress callback is not called during the DNS lookup stage.

CURLOPT_PROGRESSDATA

Pass a pointer that will be untouched by libcurl and passed as the first argument in the progress callback set with CURLOPT_PROGRESSFUNCTION.

CURLOPT_HEADERFUNCTION

Function pointer that should match the following prototype: size_t function( void *ptr, size_t size, size_t nmemb, void *userdata);. This function gets called by libcurl as soon as it has received header data. The header callback will be called once for each header and only complete header lines are passed on to the callback. Parsing headers is easy using this. The size of the data pointed to by ptr is size multiplied with nmemb. Do not assume that the header line is zero-terminated! The pointer named userdata is the one you set with the CURLOPT_WRITEHEADER option. The callback function must return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it will signal an error to the library. This will abort the transfer and return CURLE_WRITE_ERROR.

If this option is not set, or if it is set to NULL, but CURLOPT_HEADERDATA (CURLOPT_WRITEHEADER) is set to anything but NULL, the function used to accept response data will be used instead. That is, it will be the function specified with CURLOPT_WRITEFUNCTION, or if it is not specified or NULL - the default, stream-writing function.

NOTE:
The callback will be invoked for the headers of all responses received after initiating a request and not just the final response. This includes all responses which occur during authentication negotiation. If you need to operate on only the headers from the final response, you will need to collect headers in the callback yourself and use HTTP status lines, for example, to delimit response boundaries.

When a server sends a chunked encoded transfer, it may contain a trailer. That trailer is identical to a HTTP header and if such a trailer is received it is passed to the application using this callback as well. There are several ways to detect it being a trailer and not an ordinary header: 1) it comes after the response-body. 2) it comes after the final header line (CR LF) 3) a Trailer: header among the regular response-headers mention what header(s) to expect in the trailer.

CURLOPT_WRITEHEADER

(This option is also known as CURLOPT_HEADERDATA) Pass a pointer to be used to write the header part of the received data to. See also the CURLOPT_HEADERFUNCTION option above on how to set a custom get-all-headers callback.

CURLOPT_DEBUGFUNCTION

Function pointer that should match the following prototype: int curl_debug_callback (CURL *, curl_infotype, char *, size_t, void *); CURLOPT_DEBUGFUNCTION replaces the standard debug function used when CURLOPT_VERBOSE is in effect. This callback receives debug information, as specified with the curl_infotype argument. This function must return 0. The data pointed to by the char * passed to this function WILL NOT be zero-terminated, but will be exactly of the size as told by the size_t argument.

Available curl_infotype values:

CURLINFO_TEXT

The data is informational text.

CURLINFO_HEADER_IN

The data is header (or header-like) data received from the peer.

CURLINFO_HEADER_OUT

The data is header (or header-like) data sent to the peer.

CURLINFO_DATA_IN

The data is protocol data received from the peer.

CURLINFO_DATA_OUT

The data is protocol data sent to the peer.

CURLOPT_DEBUGDATA

Pass a pointer to whatever you want passed in to your CURLOPT_DEBUGFUNCTION in the last void * argument. This pointer is not used by libcurl, it is only passed to the callback.

CURLOPT_CONV_TO_NETWORK_FUNCTION

CURLOPT_CONV_FROM_NETWORK_FUNCTION

CURLOPT_CONV_FROM_UTF8_FUNCTION

Function pointers that should match the following prototype: CURLcode function(char *ptr, size_t length);

These three options apply to non-ASCII platforms only. They are available only if CURL_DOES_CONVERSIONS was defined when libcurl was built. When this is the case, curl_version_info will return the CURL_VERSION_CONV feature bit set.

The data to be converted is in a buffer pointed to by the ptr parameter. The amount of data to convert is indicated by the length parameter. The converted data overlays the input data in the buffer pointed to by the ptr parameter. CURLE_OK should be returned upon successful conversion. A CURLcode return value defined by curl.h, such as CURLE_CONV_FAILED, should be returned if an error was encountered.

CURLOPT_CONV_TO_NETWORK_FUNCTION and CURLOPT_CONV_FROM_NETWORK_FUNCTION convert between the host encoding and the network encoding. They are used when commands or ASCII data are sent/received over the network.

CURLOPT_CONV_FROM_UTF8_FUNCTION is called to convert from UTF8 into the host encoding. It is required only for SSL processing.

If you set a callback pointer to NULL, or do not set it at all, the built-in libcurl iconv functions will be used. If HAVE_ICONV was not defined when libcurl was built, and no callback has been established, conversion will return the CURLE_CONV_REQD error code.

If HAVE_ICONV is defined, CURL_ICONV_CODESET_OF_HOST must also be defined. For example:

#define CURL_ICONV_CODESET_OF_HOST "IBM-1047"

The iconv code in libcurl will default the network and UTF8 codeset names as follows:

#define CURL_ICONV_CODESET_OF_NETWORK "ISO8859-1"

#define CURL_ICONV_CODESET_FOR_UTF8 "UTF-8"

You will need to override these definitions if they are different on your system.

CURLOPT_CHUNK_BGN_FUNCTION

Function pointer that should match the following prototype: long function (const void *transfer_info, void *ptr, int remains). This function gets called by libcurl before a part of the stream is going to be transferred (if the transfer supports chunks).

The target of transfer_info parameter is a "feature depended" structure. The parameter ptr is a pointer given by CURLOPT_CHUNK_DATA. The parameter remains contains number of chunks remaining per the transfer. If the feature is not available, the parameter has zero value.

Return CURL_CHUNK_BGN_FUNC_OK if everything is as expected, CURL_CHUNK_BGN_FUNC_SKIP if you want to skip the concrete chunk or CURL_CHUNK_BGN_FUNC_FAIL to instruct libcurl to stop if some error occurred.

CURLOPT_CHUNK_END_FUNCTION

Function pointer that should match the following prototype: long function(void *ptr). This function gets called by libcurl as soon as a part of the stream has been transferred (or skipped).

Return CURL_CHUNK_END_FUNC_OK if everything is as expected or CURL_CHUNK_END_FUNC_FAIL to instruct the lib to stop if some error occurred.

CURLOPT_CHUNK_DATA

Pass a pointer that will be untouched by libcurl and passed as the ptr argument to the CURL_CHUNK_BGN_FUNTION and CURL_CHUNK_END_FUNTION.

CURLOPT_FNMATCH_FUNCTION

Function pointer that should match int function(void *ptr, const char *pattern, const char *string) prototype (see curl/curl.h). It is used internally for the wildcard matching feature.

Return CURL_FNMATCHFUNC_MATCH if pattern matches the string, CURL_FNMATCHFUNC_NOMATCH if not or CURL_FNMATCHFUNC_FAIL if an error occurred.

CURLOPT_FNMATCH_DATA

Pass a pointer that will be untouched by libcurl and passed as the ptr argument to the CURL_FNMATCH_FUNCTION.

Error Options

CURLOPT_ERRORBUFFER

Pass a char * to a buffer that the libcurl may store human readable error messages in. This may be more helpful than just the return code from curl_easy_perform. The buffer must be at least CURL_ERROR_SIZE big. Although this argument is a char *, it does not describe an input string. Therefore, the (probably undefined) contents of the buffer is NOT copied by the library. Keep the associated storage available until libcurl no longer needs it. Failing to do so will cause unusual behavior or even crashes. libcurl will need it until you call curl_easy_cleanup or you set the same option again to use a different pointer.

Use CURLOPT_VERBOSE and CURLOPT_DEBUGFUNCTION to better debug/trace why errors happen.

If the library does not return an error, the buffer may not have been touched. Do not rely on the contents in those cases.

CURLOPT_FAILONERROR

A parameter set to 1 instructs the library to fail silently if the HTTP code returned is equal to or larger than 400. The default action would be to return the page normally, ignoring that code.

This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).

You might get some amounts of headers transferred before this situation is detected, like when a "100-continue" is received as a response to a POST/PUT and a 401 or 407 is received immediately afterwards.

Network Options

CURLOPT_URL

The actual URL to deal with. The parameter should be a char * to a zero-terminated string.

If the given URL lacks the protocol part ("http://" or "https://" etc), it will attempt to guess which protocol to use based on the given hostname. If the given protocol of the set URL is not supported, libcurl will return on error (CURLE_UNSUPPORTED_PROTOCOL) when you call curl_easy_perform or curl_multi_perform. Use curl_version_info for detailed info on which protocols are supported.

The string given to CURLOPT_URL must be url-encoded and follow RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt - http://curl.haxx.se/rfc/rfc2396.txt).

The fragment part of the URI will not be send as part of the path, which was the case previously.

CURLOPT_URL is the only option that must be set before curl_easy_perform is called.

CURLOPT_PROTOCOLS can be used to limit what protocols libcurl will use for this transfer, independent of what libcurl has been compiled to support. That may be useful if you accept the URL from an external source and want to limit the accessibility.

CURLOPT_PROTOCOLS

Pass a long that holds a bitmask of CURLPROTO_* defines. If used, this bitmask limits what protocols libcurl may use in the transfer. This allows you to have a libcurl built to support a wide range of protocols but still limit specific transfers to only be allowed to use a subset of them. By default libcurl will accept all protocols it supports. See also CURLOPT_REDIR_PROTOCOLS.

NOTE:
Cafe libcurl only supports HTTP and HTTPS protocols.

CURLOPT_REDIR_PROTOCOLS

Pass a long that holds a bitmask of CURLPROTO_* defines. If used, this bitmask limits what protocols libcurl may use in a transfer that it follows to in a redirect when CURLOPT_FOLLOWLOCATION is enabled. This allows you to limit specific transfers to only be allowed to use a subset of protocols in redirections. By default libcurl will allow all protocols except for FILE and SCP.

NOTE:
Cafe libcurl only supports HTTP and HTTPS protocols.

CURLOPT_PROXY

NOTE:
Cafe libcurl automatically applies system proxy settings. For information, see Proxy Settings.

Set HTTP proxy to use. The parameter should be a char * to a zero-terminated string holding the hostname or dotted IP address. To specify port number in this string, append :[port] to the end of the hostname. The proxy string may be prefixed with [protocol]:// since any such prefix will be ignored. The proxy's port number may optionally be specified with the separate option. If not specified, libcurl will default to using port 1080 for proxies. CURLOPT_PROXYPORT.

Setting the proxy string to "" (an empty string) will explicitly disable the use of a proxy, even if there is proxy setting is specified at in system configuration.

The proxy string may be specified with a protocol:// prefix to specify alternative proxy protocols. Use socks4://, socks4a://, socks5:// or socks5h:// (the last one to enable socks5 and asking the proxy to do the resolving, also known as CURLPROXY_SOCKS5_HOSTNAME type) to request the specific SOCKS version to be used. No protocol specified, http:// and all others will be treated as HTTP proxies.

CURLOPT_PROXYPORT

Pass a long with this option to set the proxy port to connect to unless it is specified in the proxy string CURLOPT_PROXY.

CURLOPT_PROXYTYPE

Pass a long with this option to set type of the proxy. Available options for this are CURLPROXY_HTTP, CURLPROXY_HTTP_1_0, CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5_HOSTNAME. The HTTP type is default.

If you set CURLOPT_PROXYTYPE to CURLPROXY_HTTP_1_0, it will only affect how libcurl speaks to a proxy when CONNECT is used. The HTTP version used for "regular" HTTP requests is instead controlled with CURLOPT_HTTP_VERSION.

CURLOPT_NOPROXY

Pass a pointer to a zero-terminated string. The should be a comma- separated list of hosts which do not use a proxy, if one is specified. The only wildcard is a single * character, which matches all hosts, and effectively disables the proxy. Each name in this list is matched as either a domain which contains the hostname, or the hostname itself. For example, local.com would match local.com, local.com:80, and www.local.com, but not www.notlocal.com.

CURLOPT_HTTPPROXYTUNNEL

Set the parameter to 1 to make the library tunnel all operations through a given HTTP proxy. There is a big difference between using a proxy and to tunnel through it. If you do not know what this indicates, you may not want this tunneling option.

CURLOPT_LOCALPORT

Pass a long. This sets the local port number of the socket used for connection.

CURLOPT_LOCALPORTRANGE

Pass a long. This is the number of attempts libcurl should make to find a working local port number. It starts with the given CURLOPT_LOCALPORT and adds one to the number for each retry. Setting this to 1 or below will make libcurl do only one try for the exact port number. Port numbers by nature are scarce resources that will be busy at times so setting this value to something too low might cause unnecessary connection setup failures.

CURLOPT_DNS_CACHE_TIMEOUT

Pass a long, this sets the timeout in seconds. Name resolves will be kept in memory for this number of seconds. Set to zero to completely disable caching, or set to -1 to make the cached entries remain. By default, libcurl caches this info for 60 seconds.

The name resolve functions of various libc implementations do not reread name server information unless explicitly told so (for example, by calling res_init). This may cause libcurl to keep using the older server even if DHCP has updated the server info, and this may look like a DNS cache issue to the casual libcurl-app user.

CURLOPT_DNS_USE_GLOBAL_CACHE

Pass a long. If the value is 1, it instructs curl to use a global DNS cache that will survive between easy handle creations and deletions. This is not thread-safe and this will use a global variable.

WARNING:
this option is considered obsolete. Stop using it. Switch over to using the share interface instead! For information, see CURLOPT_SHARE and curl_share_init.

CURLOPT_BUFFERSIZE

Pass a long specifying your preferred size (in bytes) for the receive buffer in libcurl. The main point of this would be that the write callback gets called more often and with smaller chunks. This is just treated as a request, not an order. You cannot be guaranteed to actually get the given size.

This size is by default set as big as possible (CURL_MAX_WRITE_SIZE), so it only makes sense to use this option if you want it smaller.

CURLOPT_PORT

Pass a long specifying what remote port number to connect to, instead of the one specified in the URL or the default port for the used protocol.

CURLOPT_TCP_NODELAY

Pass a long specifying whether the TCP_NODELAY option should be set or cleared (1 = set, 0 = clear). The option is cleared by default. This will have no effect after the connection has been established.

Setting this option will disable TCP's Nagle algorithm. The purpose of this algorithm is to try to minimize the number of small packets on the network (where "small packets" indicates TCP segments less than the Maximum Segment Size (MSS) for the network).

Maximizing the amount of data sent per TCP segment is advantageous because it amortizes the overhead of the send. However, in some cases (most notably telnet or rlogin) small segments may need to be sent without delay. This is less efficient than sending larger amounts of data at a time, and can contribute to congestion on the network if overdone.

CURLOPT_ADDRESS_SCOPE

Pass a long specifying the scope_id value to use when connecting to IPv6 link-local or site-local addresses.

Names and Passwords (Authentication)

CURLOPT_USERPWD

Pass a char * as parameter, which should be [user name]:[password] to use for the connection. Use CURLOPT_HTTPAUTH to decide the authentication method.

When using NTLM, you can set the domain by prepending it to the user name and separating the domain and name with a forward (/) or backward slash (\). Like this: "domain/user:password" or "domain\user:password". Some HTTP servers (on Windows) support this style even for Basic authentication.

When using HTTP and CURLOPT_FOLLOWLOCATION, libcurl might perform several requests to possibly different hosts. libcurl will only send this user and password information to hosts using the initial hostname (unless CURLOPT_UNRESTRICTED_AUTH is set), so if libcurl follows locations to other hosts it will not send the user and password to those. This is enforced to prevent accidental information leakage.

CURLOPT_PROXYUSERPWD

Pass a char * as parameter, which should be [user name]:[password] to use for the connection to the HTTP proxy. Use CURLOPT_PROXYAUTH to decide the authentication method.

CURLOPT_USERNAME

Pass a char * as parameter, which should be pointing to the zero-terminated user name to use for the transfer.

CURLOPT_USERNAME sets the user name to be used in protocol authentication. You should not use this option together with the (older) CURLOPT_USERPWD option.

To specify the password to be used in conjunction with the user name, use the CURLOPT_PASSWORD option.

CURLOPT_PASSWORD

Pass a char * as parameter, which should be pointing to the zero-terminated password to use for the transfer.

The CURLOPT_PASSWORD option should be used in conjunction with the CURLOPT_USERNAME option.

CURLOPT_PROXYUSERNAME

Pass a char * as parameter, which should be pointing to the zero-terminated user name to use for the transfer while connecting to Proxy.

The CURLOPT_PROXYUSERNAME option should be used in same way as the CURLOPT_PROXYUSERPWD is used. In comparison to CURLOPT_PROXYUSERPWD the CURLOPT_PROXYUSERNAME allows the username to contain a colon, like in the following example: "sip:user@example.com". The CURLOPT_PROXYUSERNAME option is an alternative way to set the user name while connecting to Proxy. There is no meaning to use it together with the CURLOPT_PROXYUSERPWD option.

To specify the password to be used in conjunction with the user name, use the CURLOPT_PROXYPASSWORD option.

CURLOPT_PROXYPASSWORD

Pass a char * as parameter, which should be pointing to the zero-terminated password to use for the transfer while connecting to Proxy.

The CURLOPT_PROXYPASSWORD option should be used in conjunction with the CURLOPT_PROXYUSERNAME option.

CURLOPT_HTTPAUTH

Pass a long as parameter, which is set to a bitmask, to instruct libcurl which authentication method(s) you want it to use. If more than one bit is set, libcurl will first query the site to see which authentication methods it supports and then pick the best one you allow it to use. For some methods, this will induce an extra network round-trip. Set the actual password with the CURLOPT_USERPWD option or with the CURLOPT_USERNAME and the CURLOPT_PASSWORD options. The available bits are listed below:

CURLAUTH_BASIC

HTTP Basic authentication. This is the default choice, and the only method that is in widespread use and supported virtually everywhere. This sends the user name and password over the network in plain text, more susceptible to be captured by others.

CURLAUTH_DIGEST

HTTP Digest authentication. Digest authentication is defined in RFC 2617 (http://www.ietf.org/rfc/rfc2617.txt) and is a more secure way to do authentication over public networks than the regular old-fashioned Basic method.

CURLAUTH_NTLM

HTTP NTLM authentication. A proprietary protocol invented and used by Microsoft. It uses a challenge-response and hash concept similar to Digest, to prevent the password from being eavesdropped.

You need to build libcurl with OpenSSL support for this option to work, or build libcurl on Windows.

CURLAUTH_ANY

This is a convenience macro that sets all bits and makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure.

CURLAUTH_ANYSAFE

This is a convenience macro that sets all bits except Basic and makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure.

CURLAUTH_ONLY

This is a meta symbol. Or this value together with a single specific auth value to force libcurl to probe for unrestricted auth and if not, only that single auth algorithm is acceptable.

CURLOPT_PROXYAUTH

Pass a long as parameter, which is set to a bitmask, to instruct libcurl which authentication method(s) you want it to use for your proxy authentication. If more than one bit is set, libcurl will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. For some methods, this will induce an extra network round-trip. Set the actual name and password with the CURLOPT_PROXYUSERPWD option. The bitmask can be constructed by using a bitwise OR to combine together the bits listed above for the CURLOPT_HTTPAUTH option. As of this writing, only Basic, Digest and NTLM work.

HTTP OPTIONS

CURLOPT_AUTOREFERER

Pass a parameter set to 1 to enable this. When enabled, libcurl will automatically set the Referrer: field in requests where it follows a Location: redirect.

CURLOPT_FOLLOWLOCATION

A parameter set to 1 instructs the library to follow any Location: header that the server sends as part of an HTTP header.

This indicates that the library will resend the same request on the new location and follow new Location: headers all the way until no more such headers are returned. CURLOPT_MAXREDIRS can be used to limit the number of redirects libcurl will follow.

Libcurl can limit what protocols it will automatically follow. The accepted protocols are set with CURLOPT_REDIR_PROTOCOLS and it excludes the FILE protocol by default.

CURLOPT_UNRESTRICTED_AUTH

A parameter set to 1 instructs the library it can continue to send authentication (user+password) when following locations, even when hostname changed. This option is meaningful only when setting CURLOPT_FOLLOWLOCATION.

CURLOPT_MAXREDIRS

Pass a long. The set number will be the redirection limit. If that many redirections have been followed, the next redirect will cause an error (CURLE_TOO_MANY_REDIRECTS). This option only makes sense if the CURLOPT_FOLLOWLOCATION is used at the same time. Setting the limit to 0 will make libcurl refuse any redirect. Set it to -1 for an infinite number of redirects (which is the default).

CURLOPT_POSTREDIR

Pass a bitmask to control how libcurl acts on redirects after POSTs that get a 301 or 302 response back. A parameter with bit 0 set (value CURL_REDIR_POST_301) instructs the library to respect RFC 2616/10.3.2 (http://www.ietf.org/rfc/rfc2616.txt) and not convert POST requests into GET requests when following a 301 redirection. Setting bit 1 (value CURL_REDIR_POST_302) makes libcurl maintain the request method after a 302 redirect. CURL_REDIR_POST_ALL is a convenience define that sets both bits.

The non-RFC behavior is ubiquitous in Internet browsers, so the library performs the conversion by default to maintain consistency. However, a server may require a POST to remain a POST after such a redirection. This option is meaningful only when setting CURLOPT_FOLLOWLOCATION.

CURLOPT_PUT

A parameter set to 1 instructs the library to use HTTP PUT to transfer data. The data should be set with CURLOPT_READDATA and CURLOPT_INFILESIZE.

This option is deprecated and you should instead use CURLOPT_UPLOAD.

CURLOPT_POST

A parameter set to 1 instructs the library to do a regular HTTP post. This will also make the library use a "Content-Type: application/x-www-form-urlencoded" header. (This is by far the most commonly used POST method).

Use one of CURLOPT_POSTFIELDS or CURLOPT_COPYPOSTFIELDS options to specify what data to post and CURLOPT_POSTFIELDSIZE or CURLOPT_POSTFIELDSIZE_LARGE to set the data size.

Optionally, you can provide data to POST using the CURLOPT_READFUNCTION and CURLOPT_READDATA options but then make sure to not set CURLOPT_POSTFIELDS to anything but NULL. When providing data with a callback, transmit it using chunked transfer-encoding or set the size of the data with the CURLOPT_POSTFIELDSIZE or CURLOPT_POSTFIELDSIZE_LARGE option. To enable chunked encoding, pass in the appropriate Transfer-Encoding header, see the post-callback.c example.

You can override the default POST Content-Type: header by setting your own with CURLOPT_HTTPHEADER.

Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURLOPT_HTTPHEADER as usual.

If you use POST to a HTTP 1.1 server, you can send data without knowing the size before starting the POST if you use chunked encoding. You enable this by adding a header like "Transfer-Encoding: chunked" with CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, specify the size in the request.

When setting CURLOPT_POST to 1, it will automatically set CURLOPT_NOBODY to 0.

If you issue a POST request and then want to make a HEAD or GET using the same reused handle, explicitly set the new request type using CURLOPT_NOBODY or CURLOPT_HTTPGET or similar.

CURLOPT_POSTFIELDS

Pass a void * as parameter, which should be the full data to post in an HTTP POST operation. Make sure that the data is formatted the way you want the server to receive it. libcurl will not convert or encode it for you. Most web servers will assume this data to be url-encoded.

The pointed data are NOT copied by the library: as a consequence, they must be preserved by the calling application until the transfer finishes.

This POST is a normal application/x-www-form-urlencoded kind (and libcurl will set that Content-Type by default when this option is used), which is the most commonly used one by HTML forms. See also the CURLOPT_POST. Using CURLOPT_POSTFIELDS implies CURLOPT_POST.

If you want to do a zero byte POST, you need to set CURLOPT_POSTFIELDSIZE explicitly to zero, as setting CURLOPT_POSTFIELDS to NULL or "" just effectively disables the sending of the specified string. libcurl will instead assume that you will send the POST data using the read callback!

Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURLOPT_HTTPHEADER as usual.

To make multipart/formdata posts (aka RFC 2388 (http://www.ietf.org/rfc/rfc2388.txt) -posts), check out the CURLOPT_HTTPPOST option.

CURLOPT_POSTFIELDSIZE

If you want to post data to the server without letting libcurl perform a strlen to measure the data size, this option must be used. When this option is used you can post fully binary data, which otherwise is likely to fail. If this size is set to -1, the library will use strlen to get the size.

CURLOPT_POSTFIELDSIZE_LARGE

Pass a curl_off_t as parameter. Use this to set the size of the CURLOPT_POSTFIELDS data to prevent libcurl from performing strlen on the data to determine the size. This is the large file version of the CURLOPT_POSTFIELDSIZE option.

CURLOPT_COPYPOSTFIELDS

Pass a char * as parameter, which should be the full data to post in an HTTP POST operation. It behaves as the CURLOPT_POSTFIELDS option, but the original data are copied by the library, allowing the application to overwrite the original data after setting this option.

Because data are copied, care must be taken when using this option in conjunction with CURLOPT_POSTFIELDSIZE or CURLOPT_POSTFIELDSIZE_LARGE: If the size has not been set prior to CURLOPT_COPYPOSTFIELDS, the data are assumed to be a NUL-terminated string; else the stored size informs the library about the data byte count to copy. In any case, the size must not be changed after CURLOPT_COPYPOSTFIELDS, unless another CURLOPT_POSTFIELDS or CURLOPT_COPYPOSTFIELDS option is issued.

CURLOPT_HTTPPOST

Instructs libcurl you want a multipart/formdata HTTP POST to be made and you instruct what data to pass on to the server. Pass a pointer to a linked list of curl_httppost structs as parameter. The easiest way to create such a list, is to use curl_formadd as documented. The data in this list must remain intact until you close this curl handle again with curl_easy_cleanup.

Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURLOPT_HTTPHEADER as usual.

When setting CURLOPT_HTTPPOST, it will automatically set CURLOPT_NOBODY to 0.

CURLOPT_REFERER

Pass a pointer to a zero-terminated string as parameter. It will be used to set the Referer: header in the HTTP request sent to the remote server. This can be used to fool servers or scripts. You can also set any custom header with CURLOPT_HTTPHEADER.

CURLOPT_USERAGENT

Pass a pointer to a zero-terminated string as parameter. It will be used to set the User-Agent: header in the HTTP request sent to the remote server. This can be used to fool servers or scripts. You can also set any custom header with CURLOPT_HTTPHEADER.

CURLOPT_HTTPHEADER

Pass a pointer to a linked list of HTTP headers to pass to the server in your HTTP request. The linked list should be a fully valid list of struct curl_slist structs properly filled in. Use curl_slist_append to create the list and curl_slist_free_all to cleanup an entire list. If you add a header that is otherwise generated and used by libcurl internally, your added one will be used instead. If you add a header with no content as in 'Accept:' (no data on the right side of the colon), the internally used header will get disabled. Using this option you can add new headers, replace internal headers and remove internal headers. To add a header with no content, make the content be two quotes: "". The headers included in the linked list must not be CRLF-terminated, because curl adds CRLF after each header item. Failure to comply with this will result in strange bugs because the server will most likely ignore part of the headers you specified.

The first line in a request (containing the method, usually a GET or POST) is not a header and cannot be replaced using this option. Only the lines following the request-line are headers. Adding this method line in this list of headers will only cause your request to send an invalid header.

Pass a NULL to this to reset back to no custom headers.

The most commonly replaced headers have "shortcuts" in the options CURLOPT_COOKIE, CURLOPT_USERAGENT and CURLOPT_REFERER.

CURLOPT_HTTP200ALIASES

Pass a pointer to a linked list of aliases to be treated as valid HTTP 200 responses. Some servers respond with a custom header response line. For example, IceCast servers respond with "ICY 200 OK". By including this string in your list of aliases, the response will be treated as a valid HTTP header line such as "HTTP/1.0 200 OK".

The linked list should be a fully valid list of struct curl_slist structs, and be properly filled in. Use curl_slist_append to create the list and curl_slist_free_all to cleanup an entire list.

The alias itself is not parsed for any version strings. The protocol is assumed to match HTTP 1.0 when an alias matched.

CURLOPT_COOKIE

Pass a pointer to a zero-terminated string as parameter. It will be used to set a cookie in the HTTP request. The format of the string should be NAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie should contain.

If you need to set multiple cookies, you need to set them all using a single option and you need to concatenate them all in one single string. Set multiple cookies in one string like this: name1=content1; name2=content2; etc.

This option sets the cookie header explicitly in the outgoing request(s). If multiple requests are done due to authentication, followed redirections or similar, they will all get this cookie passed on.

Using this option multiple times will only make the latest string override the previous ones.

CURLOPT_COOKIESESSION

Pass a long set to 1 to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies or not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only.

CURLOPT_COOKIELIST

Pass a char * to a cookie string. Cookie can be either in Netscape / Mozilla format or just regular HTTP-style header (Set-Cookie: ...) format. If cURL cookie engine was not enabled it will enable its cookie engine. Passing a magic string "ALL" will erase all cookies known by cURL. Passing the special string "SESS" will only erase all session cookies known by cURL.

CURLOPT_HTTPGET

Pass a long. If the long is 1, this forces the HTTP request to get back to GET. Usable if a POST, HEAD, PUT, or a custom request has been used previously using the same curl handle.

When setting CURLOPT_HTTPGET to 1, it will automatically set CURLOPT_NOBODY to 0.

CURLOPT_HTTP_VERSION

Pass a long, set to one of the values described below. They force libcurl to use the specific HTTP versions. This is not sensible to do unless you have a good reason.

CURL_HTTP_VERSION_NONE

It is of no matter what version the library uses. libcurl will use whatever it deems as a good fit.

CURL_HTTP_VERSION_1_0

Enforce HTTP 1.0 requests.

CURL_HTTP_VERSION_1_1

Enforce HTTP 1.1 requests.

CURLOPT_IGNORE_CONTENT_LENGTH

Ignore the Content-Length header. This is useful for Apache 1.x (and similar servers) which will report incorrect content length for files over 2 gigabytes. If this option is used, curl will not be able to accurately report progress, and will stop the download when the server ends the connection.

CURLOPT_HTTP_CONTENT_DECODING

Pass a long to instruct libcurl how to act on content decoding. If set to zero, content decoding will be disabled. If set to 1 it is enabled. Libcurl has no default content decoding but requires you to use CURLOPT_ENCODING for that.

CURLOPT_HTTP_TRANSFER_DECODING

Pass a long to instruct libcurl how to act on transfer decoding. If set to zero, transfer decoding will be disabled, if set to 1 it is enabled (default). libcurl does chunked transfer decoding by default unless this option is set to zero.

CURLOPT_CUSTOM_HEADERS_IN_CONNECT

By default, custom headers are included in CONNECT requests made from libcurl. To disable custom headers in CONNECT requests, use this option in curl_easy_setopt with a value of 0. To again enable custom headers, use this option with a value of 1. This option also controls the inclusion of the user-agent field (if set with CURLOPT_USERAGENT), which is also included in CONNECT requests by default.

To enable: curl_easy_setopt(curl, CURLOPT_CUSTOM_HEADERS_IN_CONNECT, 1);

To disable: curl_easy_setopt(curl, CURLOPT_CUSTOM_HEADERS_IN_CONNECT, 0);

PROTOCOL OPTIONS

CURLOPT_CRLF

Pass a long. If the value is set to 1 (one), libcurl converts Unix newlines to CRLF newlines on transfers. Disable this option again by setting the value to 0 (zero).

CURLOPT_RANGE

Pass a char * as parameter, which should contain the specified range you want. It should be in the format "X-Y", where X or Y may be left out. HTTP transfers also support several intervals, separated with commas as in "X-Y,N-M". Using this type of multiple intervals will cause the HTTP server to send the response document in pieces (using standard MIME separation techniques). For RTSP, the formatting of a range should follow RFC 2326 (http://www.ietf.org/rfc/rfc2326.txt) Section 12.29. For RTSP, byte ranges are not permitted. Instead, ranges should be given in npt, utc, or smpte formats.

Pass a NULL to this option to disable the use of ranges.

CURLOPT_RESUME_FROM

Pass a long as parameter. It contains the offset in number of bytes that you want the transfer to start from. Set this option to 0 to make the transfer start from the beginning (effectively disabling resume).

CURLOPT_RESUME_FROM_LARGE

Pass a curl_off_t as a parameter. It contains the offset, in bytes, that you want the transfer to start from.

CURLOPT_CUSTOMREQUEST

Pass a pointer to a zero-terminated string as parameter. It will be used instead of GET or HEAD when performing an HTTP request. This is useful for performing DELETE or other more or less obscure HTTP requests. Do not do this at will, make sure your server supports the command first.

When you change the request method by setting CURLOPT_CUSTOMREQUEST to something, you do not actually change how libcurl behaves or acts in regards to the particular request method, it will only change the actual string sent in the request.

For example: if you instruct libcurl to do a HEAD request, but then change the request to a "GET" with CURLOPT_CUSTOMREQUEST you will still see libcurl act as if it sent a HEAD even when it does send a GET.

To switch to a proper HEAD, use CURLOPT_NOBODY, to switch to a proper POST, use CURLOPT_POST or CURLOPT_POSTFIELDS and so on.

Restore to the internal default by setting this to NULL.

Many users have incorrectly used this option to replace the entire request with their own, including multiple headers and POST contents. While that might work in many cases, it will cause libcurl to send invalid requests and it could possibly confuse the remote server badly. Use CURLOPT_POST and CURLOPT_POSTFIELDS to set POST data. Use CURLOPT_HTTPHEADER to replace or extend the set of headers sent by libcurl. Use CURLOPT_HTTP_VERSION to change HTTP version.

CURLOPT_FILETIME

Pass a long. If it is 1, libcurl will attempt to get the modification date of the remote document in this operation. This requires that the remote server sends the time or replies to a time querying command. The curl_easy_getinfo function with the CURLINFO_FILETIME argument can be used after a transfer to extract the received time (if any).

CURLOPT_NOBODY

A parameter set to 1 instructs the library to not include the body-part in the output. This is only relevant for protocols that have separate header and body parts. On HTTP(S) servers, this will make libcurl do a HEAD request.

To change request to GET, you should use CURLOPT_HTTPGET. Change request to POST with CURLOPT_POST etc.

CURLOPT_INFILESIZE

When uploading a file to a remote site, this option should be used to instruct libcurl what the expected size of the infile is. This value should be passed as a long. See also CURLOPT_INFILESIZE_LARGE.

This option does not limit how much data libcurl will actually send, as that is controlled entirely by what the read callback returns.

CURLOPT_INFILESIZE_LARGE

When uploading a file to a remote site, this option should be used to instruct libcurl what the expected size of the infile is. This value should be passed as a curl_off_t.

This option does not limit how much data libcurl will actually send, as that is controlled entirely by what the read callback returns.

CURLOPT_UPLOAD

A parameter set to 1 instructs the library to prepare for an upload. The CURLOPT_READDATA and CURLOPT_INFILESIZE or CURLOPT_INFILESIZE_LARGE options are also interesting for uploads. If the protocol is HTTP, uploading indicates using the PUT request unless you instruct libcurl otherwise.

Using PUT with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURLOPT_HTTPHEADER as usual.

If you use PUT to a HTTP 1.1 server, you can upload data without knowing the size before starting the transfer if you use chunked encoding. You enable this by adding a header like "Transfer-Encoding: chunked" with CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, specify the size.

CURLOPT_MAXFILESIZE

Pass a long as parameter. This allows you to specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer will not start and CURLE_FILESIZE_EXCEEDED will be returned.

The file size is not always known prior to download, and for such files this option has no effect even if the file transfer ends up being larger than this given limit.

CURLOPT_MAXFILESIZE_LARGE

Pass a curl_off_t as parameter. This allows you to specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer will not start and CURLE_FILESIZE_EXCEEDED will be returned.

The file size is not always known prior to download, and for such files this option has no effect even if the file transfer ends up being larger than this given limit.

CURLOPT_TIMECONDITION

Pass a long as parameter. This defines how the CURLOPT_TIMEVALUE time value is treated. You can set this parameter to CURL_TIMECOND_IFMODSINCE or CURL_TIMECOND_IFUNMODSINCE.

The last modification time of a file is not always known and in such instances this feature will have no effect even if the given time condition would not have been met. curl_easy_getinfo with the CURLINFO_CONDITION_UNMET option can be used after a transfer to learn if a zero byte successful "transfer" was due to this condition not matching.

CURLOPT_TIMEVALUE

Pass a long as parameter. This should be the time in seconds since 1 Jan 1970, and the time will be used in a condition as specified with CURLOPT_TIMECONDITION.

CONNECTION OPTIONS

CURLOPT_TIMEOUT

Pass a long as parameter containing the maximum time in seconds that you allow the libcurl transfer operation to take. Normally, name lookups can take a considerable time and limiting operations to less than a few minutes risk aborting normal operations. This option will cause curl to use the SIGALRM to enable time-outing system calls.

CURLOPT_TIMEOUT_MS

Like CURLOPT_TIMEOUT but takes number of milliseconds instead. If libcurl is built to use the standard system name resolver, that portion of the transfer will still use full-second resolution for timeouts with a minimum timeout allowed of one second.

CURLOPT_LOW_SPEED_LIMIT

Pass a long as parameter. It contains the transfer speed in bytes per second that the transfer should be below during CURLOPT_LOW_SPEED_TIME seconds for the library to consider it too slow and abort.

CURLOPT_LOW_SPEED_TIME

Pass a long as parameter. It contains the time in seconds that the transfer should be below the CURLOPT_LOW_SPEED_LIMIT for the library to consider it too slow and abort.

CURLOPT_MAX_SEND_SPEED_LARGE

Pass a curl_off_t as parameter. If an upload exceeds this speed (counted in bytes per second) on cumulative average during the transfer, the transfer will pause to keep the average rate less than or equal to the parameter value. Defaults to unlimited speed.

CURLOPT_MAX_RECV_SPEED_LARGE

Pass a curl_off_tt as parameter. If a download exceeds this speed (counted in bytes per second) on cumulative average during the transfer, the transfer will pause to keep the average rate less than or equal to the parameter value. Defaults to unlimited speed.

CURLOPT_MAXCONNECTS

Pass a long. The set number will be the persistent connection cache size. The set amount will be the maximum amount of simultaneously open connections that libcurl may cache in this easy handle. Default is 5, and there is no reason to change this value unless you are aware of how this works and changes libcurl's behavior. This concerns connections using any of the protocols that support persistent connections.

When reaching the maximum limit, curl closes the oldest one in the cache to prevent increasing the number of open connections.

If you already have performed transfers with this curl handle, setting a smaller MAXCONNECTS than before may cause open connections to get closed unnecessarily.

If you add this easy handle to a multi handle, this setting is not acknowledged, instead use curl_multi_setopt and the CURLMOPT_MAXCONNECTS option.

CURLOPT_CLOSEPOLICY

(Obsolete) This option does nothing.

CURLOPT_FRESH_CONNECT

Pass a long. Set to 1 to make the next transfer use a new (fresh) connection by force. If the connection cache is full before this connection, one of the existing connections will be closed as according to the selected or default policy. This option should be used with caution and only if you understand what it does. Set this to 0 to have libcurl attempt reusing an existing connection (default behavior).

CURLOPT_FORBID_REUSE

Pass a long. Set to 1 to make the next transfer explicitly close the connection when done. Normally, libcurl keeps all connections alive when done with one transfer in case a succeeding one follows that can reuse them. This option should be used with caution and only if you understand what it does. Set to 0 to have libcurl keep the connection open for possible later reuse (default behavior).

CURLOPT_CONNECTTIMEOUT

Pass a long. It should contain the maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once it has connected, this option is of no more use. Set to zero to disable connection timeout (it will then only timeout on the system's internal timeouts). See also the CURLOPT_TIMEOUT option.

In some systems this might cause signals to be used unless CURLOPT_NOSIGNAL is set. However, our system does not use signals, so the application will not be affected by signals. This also means that CURLOPT_NOSIGNAL is not supported.

CURLOPT_CONNECTTIMEOUT_MS

Like CURLOPT_CONNECTTIMEOUT but takes the number of milliseconds instead. If libcurl is built to use the standard system name resolver, that portion of the connect will still use full-second resolution for timeouts with a minimum timeout allowed of one second.

CURLOPT_IPRESOLVE

Allows an application to select what type of IP addresses to use when resolving hostnames. This is only interesting when using hostnames that resolve addresses using more than one version of IP. The allowed values are:

CURL_IPRESOLVE_WHATEVER

Default, resolves addresses to all IP versions that your system allows.

CURL_IPRESOLVE_V4

Resolve to IPv4 addresses.

CURLOPT_CONNECT_ONLY

Pass a long. If the parameter equals 1, it instructs the library to perform all the required proxy authentication and connection setup, but no data transfer. This option is useful only on HTTP URLs.

This option is useful with the CURLINFO_LASTSOCKET option to curl_easy_getinfo. The library can set up the connection and then the application can obtain the most recently used socket for special data transfers.

CURLOPT_RESOLVE

Pass a pointer to a linked list of strings with hostname resolve information to use for requests with this handle. The linked list should be a fully valid list of struct curl_slist structs properly filled in. Use curl_slist_append to create the list and curl_slist_free_all to cleanup an entire list.

Each single name resolve string should be written using the format HOST:PORT:ADDRESS where HOST is the name libcurl will try to resolve, PORT is the port number of the service where libcurl wants to connect to the HOST and ADDRESS is the numerical IP address. If libcurl is built to support IPv6, ADDRESS can be either IPv4 or IPv6 style addressing.

This option effectively prepopulates the DNS cache with entries for the host+port pair so redirects and everything that operations against the HOST+PORT will instead use your provided ADDRESS.

You can remove names from the DNS cache again, to stop providing these fake resolves, by including a string in the linked list that uses the format -HOST:PORT. The hostname must be prefixed with a dash, and the hostname and port number must exactly match what was already added previously.

SSL and SECURITY OPTIONS

Cafe libcurl uses its own SSL library to support HTTPS. For more information, see HTTPS section.

CURLOPT_NSSL_CONTEXT

Pass a NSSLContext (created using NSSLCreateContext) to be used for the HTTPS transfers. Setup the NSSLContext to use appropriate client and trusted CA certificates to be used for SSL handshake.

CURLOPT_NSSL_PEER_VERIFY_OPT

Pass a bitmask (int) specifying peer validation options to be used for SSL handshake. If not specified, NSSL_VERIFY_ALL_EXCEPT_DATE (i.e. validate peer certificate's CA and hostname but ignore ValidFrom and ValidTo dates) is used. It can be a bitwise OR combination of any of the following.

NSSL_VERIFY_NONE: Do not verify peer certificate.

NSSL_VERIFY_PEER_CA: Validate the peer certificate using the server certificates specified using NSSLAddServerPKIExternal

NOTE:
Peer certificate's ValidFrom and ValidTo dates are not checked unless NSSL_VERIFY_DATE_VALIDITY bit is also set.

NSSL_VERIFY_HOSTNAME: In addition to peer certificate validation (see NSSL_VERIFY_PEER_CA), also check if the hostname matches the Common Name field or a Subject Alternate Name field in the peer certificate.

NOTE:
If NSSL_VERIFY_HOSTNAME is set, NSSL_VERIFY_PEER_CA is assumed to be set.

NSSL_VERIFY_DATE_VALIDITY: Validate peer certificate's ValidFrom and ValidTo dates.

NSSL_VERIFY_ALL: (NSSL_VERIFY_PEER_CA | NSSL_VERIFY_HOSTNAME | NSSL_VERIFY_DATE_VALIDITY)

NSSL_VERIFY_ALL_EXCEPT_DATE: (NSSL_VERIFY_PEER_CA | NSSL_VERIFY_HOSTNAME)

OTHER OPTIONS

CURLOPT_PRIVATE

Pass a void * as parameter, pointing to data that should be associated with this curl handle. The pointer can subsequently be retrieved using curl_easy_getinfo with the CURLINFO_PRIVATE option. libcurl itself does nothing with this data.

CURLOPT_SHARE

Pass a share handle as a parameter. The share handle must have been created by a previous call to curl_share_init. Setting this option, will make this curl handle use the data from the shared handle instead of keeping the data to itself. This enables several curl handles to share data. If the curl handles are used simultaneously in multiple threads, you MUST use the locking methods in the share handle. For more information, see curl_share_setopt.

If you add a share that is set to share cookies, your easy handle will use that cookie cache and get the cookie engine enabled. If you unshare an object that was using cookies (or change to another object that does not share cookies), the easy handle will get its cookie engine disabled.

Data that the share object is not set to share will be dealt with the usual way, as if no share was used.

Do Not Call From

None.

See Also

HTTP Client Library (libcurl)
libcurl API Functions
libcurl Error Codes
curl_easy_init
curl_easy_cleanup
curl_easy_reset

Revision History

2014/06/24 Reworked external link.
2014/01/22 Added CURLOPT_CUSTOM_HEADERS_IN_CONNECT option
2013/09/18 Conversion
2013/05/08 Automated cleanup pass.
2012/05/04 Initial version.


CONFIDENTIAL