📄 curl_easy_setopt.3
字号:
.\" nroff -man [file].\" $Id: curl_easy_setopt.3,v 1.55 2003/10/17 13:11:01 bagder Exp $.\".TH curl_easy_setopt 3 "16 Oct 2003" "libcurl 7.10.8" "libcurl Manual".SH NAMEcurl_easy_setopt - set options for a curl easy handle.SH SYNOPSIS#include <curl/curl.h>CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter);.ad.SH DESCRIPTIONcurl_easy_setopt() is used to tell libcurl how to behave. By using theappropriate options to \fIcurl_easy_setopt\fP, you can change libcurl'sbehavior. All options are set with the \fIoption\fP followed by a\fIparameter\fP. That parameter can be a long, a function pointer or an objectpointer, all depending on what the specific option expects. Read this manualcarefully as bad input values may cause libcurl to behave badly! You can onlyset one option in each function call. A typical application uses manycurl_easy_setopt() calls in the setup phase.\fBNOTE:\fP strings passed to libcurl as 'char *' arguments, will not becopied by the library. Instead you should keep them available until libcurl nolonger needs them. Failing to do so will cause very odd behavior or evencrashes. libcurl will need them until you call curl_easy_cleanup() or you setthe same option again to use a different pointer.\fBNOTE2:\fP options set with this function call are valid for the forthcomingdata transfers that are performed when you invoke \fIcurl_easy_perform\fP.The options are not in any way reset between transfers, so if you wantsubsequent transfers with different options, you must change them between thetransfers.The \fIhandle\fP is the return code from a \fIcurl_easy_init(3)\fP or\fIcurl_easy_duphandle(3)\fP call..SH BEHAVIOR OPTIONS.TP 0.4i.B CURLOPT_VERBOSESet the parameter to non-zero to get the library to display a lot of verboseinformation about its operations. Very useful for libcurl and/or protocoldebugging and understanding.You hardly ever want this set in production use, you will almost always wantthis when you debug/report problems. Another neat option for debugging is the\fICURLOPT_DEBUGFUNCTION\fP..TP.B CURLOPT_HEADERA non-zero parameter tells the library to include the header in the bodyoutput. This is only relevant for protocols that actually have headerspreceding the data (like HTTP)..TP.B CURLOPT_NOPROGRESSA non-zero parameter tells the library to shut of the built-in progress metercompletely.\fBNOTE:\fP future versions of libcurl is likely to not have any built-inprogress meter at all..TP.B CURLOPT_NOSIGNALPass a long. If it is non-zero, libcurl will not use any functions thatinstall signal handlers or any functions that cause signals to be sent to theprocess. This option is mainly here to allow multi-threaded unix applicationsto still set/use all timeout options etc, without risking getting signals.(Added in 7.10).PP.SH CALLBACK OPTIONS.TP 0.4i.B CURLOPT_WRITEFUNCTIONFunction pointer that should match the following prototype: \fBsize_tfunction( void *ptr, size_t size, size_t nmemb, void *stream);\fP Thisfunction gets called by libcurl as soon as there is data reveiced that needsto be saved. The size of the data pointed to by \fIptr\fP is \fIsize\fPmultiplied with \fInmemb\fP, it will not be zero terminated. Return the numberof bytes actually taken care of. If that amount differs from the amount passedto your function, it'll signal an error to the library and it will abort thetransfer and return \fICURLE_WRITE_ERROR\fP.Set the \fIstream\fP argument with the \fBCURLOPT_WRITEDATA\fP option.\fBNOTE:\fP you will be passed as much data as possible in all invokes, butyou cannot possibly make any assumptions. It may be one byte, it may bethousands. The maximum amount of data that can be passed to the write callbackis defined in the curl.h header file: CURL_MAX_WRITE_SIZE..TP.B CURLOPT_WRITEDATAData pointer to pass to the file write function. Note that if you specify the\fICURLOPT_WRITEFUNCTION\fP, this is the pointer you'll get as input. If youdon't use a callback, you must pass a 'FILE *' as libcurl will pass this tofwrite() when writing data.\fBNOTE:\fP If you're using libcurl as a win32 DLL, you MUST use the\fICURLOPT_WRITEFUNCTION\fP if you set this option or you will experiencecrashes.This option is also known with the older name \fBCURLOPT_FILE\fP, the nameCURLOPT_WRITEDATA was introduced in 7.9.7..TP.B CURLOPT_READFUNCTIONFunction pointer that should match the following prototype: \fBsize_tfunction( void *ptr, size_t size, size_t nmemb, void *stream);\fP Thisfunction gets called by libcurl as soon as it needs to read data in order tosend it to the peer. The data area pointed at by the pointer \fIptr\fP may befilled with at most \fIsize\fP multiplied with \fInmemb\fP number ofbytes. Your function must return the actual number of bytes that you stored inthat memory area. Returning 0 will signal end-of-file to the library and causeit to stop the current transfer..TP.B CURLOPT_READDATAData pointer to pass to the file read function. Note that if you specify the\fICURLOPT_READFUNCTION\fP, this is the pointer you'll get as input. If youdon't specify a read callback, this must be a valid FILE *.\fBNOTE:\fP If you're using libcurl as a win32 DLL, you MUST use a\fICURLOPT_READFUNCTION\fP if you set this option.This option is also known with the older name \fBCURLOPT_INFILE\fP, the nameCURLOPT_READDATA was introduced in 7.9.7..TP.B CURLOPT_PROGRESSFUNCTIONFunction pointer that should match the \fIcurl_progress_callback\fP prototypefound in \fI<curl/curl.h>\fP. This function gets called by libcurl instead ofits internal equivalent with a frequent interval during data transfer.Unknown/unused argument values will be set to zero (like if you only downloaddata, the upload size will remain 0). Returning a non-zero value from thiscallback will cause libcurl to abort the transfer and return\fICURLE_ABORTED_BY_CALLBACK\fP.Also note that \fICURLOPT_NOPROGRESS\fP must be set to FALSE to make thisfunction actually get called..TP.B CURLOPT_PROGRESSDATAPass a pointer that will be untouched by libcurl and passed as the firstargument in the progress callback set with \fICURLOPT_PROGRESSFUNCTION\fP..TP.B CURLOPT_HEADERFUNCTIONFunction pointer that should match the following prototype: \fIsize_tfunction( void *ptr, size_t size, size_t nmemb, void *stream);\fP. Thisfunction gets called by libcurl as soon as there is received header data thatneeds to be written down. The headers are guaranteed to be written one-by-oneand only complete lines are written. Parsing headers should be easy enoughusing this. The size of the data pointed to by \fIptr\fP is \fIsize\fPmultiplied with \fInmemb\fP. The pointer named \fIstream\fP will be the oneyou passed to libcurl with the \fICURLOPT_WRITEHEADER\fP option. Return thenumber of bytes actually written or return -1 to signal error to the library(it will cause it to abort the transfer with a \fICURLE_WRITE_ERROR\fP returncode)..TP.B CURLOPT_WRITEHEADERPass a pointer to be used to write the header part of the received data to. Ifyou don't use your own callback to take care of the writing, this must be avalid FILE *. See also the \fICURLOPT_HEADERFUNCTION\fP option above on how toset a custom get-all-headers callback..TP.B CURLOPT_DEBUGFUNCTIONFunction pointer that should match the following prototype: \fIintcurl_debug_callback (CURL *, curl_infotype, char *, size_t, void *);\fPCURLOPT_DEBUGFUNCTION replaces the standard debug function used whenCURLOPT_VERBOSE is in effect. This callback receives debug information, asspecified with the \fIcurl_infotype\fP argument. This funtion must return 0.The data pointed to by the char * passed to this function WILL NOT be zeroterminated, but will be exactly of the size as told by the size_t argument.Available curl_infotype values:.RS.TP 5.B CURLINFO_TEXTThe data is informational text..TP.B CURLINFO_HEADER_INThe data is header (or header-like) data received from the peer..TP.B CURLINFO_HEADER_OUTThe data is header (or header-like) data sent to the peer..TP.B CURLINFO_DATA_INThe data is protocol data received from the peer..TP.B CURLINFO_DATA_OUTThe data is protocol data sent to the peer..RE.TP.B CURLOPT_DEBUGDATAPass a pointer to whatever you want passed in to your CURLOPT_DEBUGFUNCTION inthe last void * argument. This pointer is not used by libcurl, it is onlypassed to the callback..PP.SH ERROR OPTIONS.TP 0.4i.B CURLOPT_ERRORBUFFERPass a char * to a buffer that the libcurl may store human readable errormessages in. This may be more helpful than just the return code from thelibrary. The buffer must be at least CURL_ERROR_SIZE big.Use \fICURLOPT_VERBOSE\fP and \fICURLOPT_DEBUGFUNCTION\fP to betterdebug/trace why errors happen.\fBNote:\fP if the library does not return an error, the buffer may not havebeen touched. Do not rely on the contents in those cases..TP.B CURLOPT_STDERRPass a FILE * as parameter. This is the stream to use instead of stderrinternally when reporting errors..TP.B CURLOPT_FAILONERRORA non-zero parameter tells the library to fail silently if the HTTP codereturned is equal to or larger than 300. The default action would be to returnthe page normally, ignoring that code..PP.SH NETWORK OPTIONS.TP 0.4i.B CURLOPT_URLThe actual URL to deal with. The parameter should be a char * to a zeroterminated string. The string must remain present until curl no longer needsit, as it doesn't copy the string.\fBNOTE:\fP this option is (the only one) required to be set before\fIcurl_easy_perform(3)\fP is called..TP.B CURLOPT_PROXYSet HTTP proxy to use. The parameter should be a char * to a zero terminatedstring holding the host name or dotted IP address. To specify port number inthis string, append :[port] to the end of the host name. The proxy string maybe prefixed with [protocol]:// since any such prefix will be ignored. Theproxy's port number may optionally be specified with the separate option\fICURLOPT_PROXYPORT\fP.\fBNOTE:\fP when you tell the library to use a HTTP proxy, libcurl willtransparently convert operations to HTTP even if you specify a FTP URLetc. This may have an impact on what other features of the library you canuse, such as CURLOPT_QUOTE and similar FTP specifics that don't work unlessyou tunnel through the HTTP proxy. Such tunneling is activated with\fICURLOPT_HTTPPROXYTUNNEL\fP.\fBNOTE2:\fP libcurl respects the environment variables \fBhttp_proxy\fP,\fBftp_proxy\fP, \fBall_proxy\fP etc, if any of those is set..TP.B CURLOPT_PROXYPORTPass a long with this option to set the proxy port to connect to unless it isspecified in the proxy string \fICURLOPT_PROXY\fP..TP.B CURLOPT_PROXYTYPEPass a long with this option to set type of the proxy. Available options forthis are CURLPROXY_HTTP and CURLPROXY_SOCKS5, with the HTTP one beingdefault. (Added in 7.10).TP.B CURLOPT_HTTPPROXYTUNNELSet the parameter to non-zero to get the library to tunnel all operationsthrough a given HTTP proxy. Note that there is a big difference between usinga proxy and to tunnel through it. If you don't know what this means, youprobably don't want this tunneling option..TP.B CURLOPT_INTERFACEPass a char * as parameter. This set the interface name to use as outgoingnetwork interface. The name can be an interface name, an IP address or a hostname..TP.B CURLOPT_DNS_CACHE_TIMEOUTPass a long, this sets the timeout in seconds. Name resolves will be kept inmemory for this number of seconds. Set to zero (0) to completely disablecaching, or set to -1 to make the cached entries remain forever. By default,libcurl caches info for 60 seconds..TP.B CURLOPT_DNS_USE_GLOBAL_CACHEPass a long. If the value is non-zero, it tells curl to use a global DNS cachethat will survive between easy handle creations and deletions. This is notthread-safe and this will use a global varible..TP.B CURLOPT_BUFFERSIZEPass a long specifying your prefered size for the receive buffer in libcurl.The main point of this would be that the write callback gets called more oftenand with smaller chunks. This is just treated as a request, not an order. Youcannot be guaranteed to actually get the given size. (Added in 7.10).PP.SH NAMES and PASSWORDS OPTIONS (Authentication).TP 0.4i.B CURLOPT_NETRCThis parameter controls the preference of libcurl between using user names andpasswords from your \fI~/.netrc\fP file, relative to user names and passwordsin the URL supplied with \fICURLOPT_URL\fP.\fBNote:\fP libcurl uses a user name (and supplied or prompted password)supplied with \fICURLOPT_USERPWD\fP in preference to any of the optionscontrolled by this parameter.Pass a long, set to one of the values described below..RS.TP 5.B CURL_NETRC_OPTIONALThe use of your \fI~/.netrc\fP file is optional,and information in the URL is to be preferred. The file will be scannedwith the host and user name (to find the password only) or with the host only,to find the first user name and password after that \fImachine\fP,which ever information is not specified in the URL.Undefined values of the option will have this effect..TP .B CURL_NETRC_IGNOREDThe library will ignore the file and use only the information in the URL.This is the default..TP.B CURL_NETRC_REQUIREDThis value tells the library that use of the file is required,to ignore the information in the URL,and to search the file with the host only..RE.TPOnly machine name, user name and password are taken into account (init macros and similar things aren't supported).\fBNote:\fP libcurl does not verify that the file has the correct propertiesset (as the standard Unix ftp client does). It should only be readable by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -