📄 curl_easy_setopt.3
字号:
.\" **************************************************************************.\" * _ _ ____ _.\" * Project ___| | | | _ \| |.\" * / __| | | | |_) | |.\" * | (__| |_| | _ <| |___.\" * \___|\___/|_| \_\_____|.\" *.\" * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al..\" *.\" * This software is licensed as described in the file COPYING, which.\" * you should have received as part of this distribution. The terms.\" * are also available at http://curl.haxx.se/docs/copyright.html..\" *.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell.\" * copies of the Software, and permit persons to whom the Software is.\" * furnished to do so, under the terms of the COPYING file..\" *.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY.\" * KIND, either express or implied..\" *.\" * $Id: curl_easy_setopt.3,v 1.153 2006-08-02 09:33:32 bagder Exp $.\" **************************************************************************.\".TH curl_easy_setopt 3 "19 Apr 2006" "libcurl 7.15.4" "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);.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 \fBlong\fP, a \fBfunction pointer\fP,an \fBobject pointer\fP or a \fBcurl_off_t\fP, depending on what the specificoption expects. Read this manual carefully as bad input values may causelibcurl to behave badly! You can only set one option in each function call. Atypical application uses many curl_easy_setopt() calls in the setup phase.Options set with this function call are valid for all forthcoming transfersperformed using this \fIhandle\fP. The options are not in any way resetbetween transfers, so if you want subsequent transfers with different options,you must change them between the transfers. You can optionally reset alloptions back to internal default with \fIcurl_easy_reset(3)\fP.Strings passed to libcurl as 'char *' arguments, will not be copied by thelibrary. Instead you should keep them available until libcurl no longer needsthem. Failing to do so will cause very odd behavior or even crashes. libcurlwill need them until you call \fIcurl_easy_cleanup(3)\fP or you set the sameoption again to use a different pointer.The \fIhandle\fP is the return code from a \fIcurl_easy_init(3)\fP or\fIcurl_easy_duphandle(3)\fP call..SH BEHAVIOR OPTIONS.IP 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. The verbose information will be sent to stderr,or the stream set with \fICURLOPT_STDERR\fP.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..IP 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)..IP CURLOPT_NOPROGRESSA non-zero parameter tells the library to shut off the built-in progress metercompletely.Future versions of libcurl is likely to not have any built-in progress meterat all..IP 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)Consider building libcurl with ares support to enable asynchronous DNSlookups. It enables nice timeouts for name resolves without signals..PP.SH CALLBACK OPTIONS.IP 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 received 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.This function may be called with zero bytes data if the transfered file isempty.Set this option to NULL to get the internal default function. The internaldefault function will write the data to the FILE * given with\fICURLOPT_WRITEDATA\fP.Set the \fIstream\fP argument with the \fICURLOPT_WRITEDATA\fP 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 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..IP CURLOPT_WRITEDATAData pointer to pass to the file write function. If you use the\fICURLOPT_WRITEFUNCTION\fP option, this is the pointer you'll get asinput. If you don't use a callback, you must pass a 'FILE *' as libcurl willpass this to fwrite() when writing data.The internal \fICURLOPT_WRITEFUNCTION\fP will write the data to the FILE *given with this option, or to stdout if this option hasn't been set.If you're using libcurl as a win32 DLL, you \fBMUST\fP use the\fICURLOPT_WRITEFUNCTION\fP if you set this option or you will experiencecrashes.This option is also known with the older name \fICURLOPT_FILE\fP, the name\fICURLOPT_WRITEDATA\fP was introduced in 7.9.7..IP 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.If you stop the current transfer by returning 0 "pre-maturely" (i.e before theserver expected it, like when you've told you will upload N bytes and youupload less than N bytes), you may experience that the server "hangs" waitingfor the rest of the data that won't come.The read callback may return \fICURL_READFUNC_ABORT\fP to stop the currentoperation immediately, resulting in a \fICURLE_ABORTED_BY_CALLBACK\fP errorcode from the transfer (Added in 7.12.1)If you set the callback pointer to NULL, or doesn't set it at all, the defaultinternal read function will be used. It is simply doing an fread() on the FILE* stream set with \fICURLOPT_READDATA\fP..IP CURLOPT_READDATAData pointer to pass to the file read function. If you use the\fICURLOPT_READFUNCTION\fP option, this is the pointer you'll get as input. Ifyou don't specify a read callback but instead rely on the default internalread function, this data must be a valid readable FILE *.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 \fICURLOPT_INFILE\fP, the name\fICURLOPT_READDATA\fP was introduced in 7.9.7..IP CURLOPT_IOCTLFUNCTIONFunction pointer that should match the \fIcurl_ioctl_callback\fP prototypefound in \fI<curl/curl.h>\fP. This function gets called by libcurl whensomething special I/O-related needs to be done that the library can't do byitself. For now, rewinding the read data stream is the only action it canrequest. The rewinding of the read data stream may be necessary when doing aHTTP PUT or POST with a multi-pass authentication method. (Opion added in7.12.3).IP CURLOPT_IOCTLDATAPass a pointer that will be untouched by libcurl and passed as the 3rdargument in the ioctl callback set with \fICURLOPT_IOCTLFUNCTION\fP. (Optionadded in 7.12.3).IP 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 operation (roughlyonce per second) no matter if data is being transfered or not. Unknown/unusedargument values passed to the callback will be set to zero (like if you onlydownload data, the upload size will remain 0). Returning a non-zero value fromthis callback will cause libcurl to abort the transfer and return\fICURLE_ABORTED_BY_CALLBACK\fP.If you transfer data with the multi interface, this function will not becalled during periods of idleness unless you call the appropriate libcurlfunction that performs transfers. Usage of the \fBCURLOPT_PROGRESSFUNCTION\fPcallback is not recommended when using the multi interface.\fICURLOPT_NOPROGRESS\fP must be set to FALSE to make this function actuallyget called..IP CURLOPT_PROGRESSDATAPass a pointer that will be untouched by libcurl and passed as the firstargument in the progress callback set with \fICURLOPT_PROGRESSFUNCTION\fP..IP 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 it has received header data. Theheader callback will be called once for each header and only complete headerlines are passed on to the callback. Parsing headers should be easy enoughusing this. The size of the data pointed to by \fIptr\fP is \fIsize\fPmultiplied with \fInmemb\fP. Do not assume that the header line is zeroterminated! The pointer named \fIstream\fP is the one you set with the\fICURLOPT_WRITEHEADER\fP option. The callback function must return the numberof bytes actually taken care of, or return -1 to signal error to the library(it will cause it to abort the transfer with a \fICURLE_WRITE_ERROR\fP returncode).Since 7.14.1: When a server sends a chunked encoded transfer, it may contain atrailer. That trailer is identical to a HTTP header and if such a trailer isreceived it is passed to the application using this callback as well. Thereare 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 (CRLF) 3) a Trailer: header among the response-headers mention what header toexpect in the trailer..IP CURLOPT_WRITEHEADER(This option is also known as \fBCURLOPT_HEADERDATA\fP) Pass a pointer to beused to write the header part of the received data to. If you don't use yourown callback to take care of the writing, this must be a valid FILE *. Seealso the \fICURLOPT_HEADERFUNCTION\fP option above on how to set a customget-all-headers callback..IP CURLOPT_DEBUGFUNCTIONFunction pointer that should match the following prototype: \fIintcurl_debug_callback (CURL *, curl_infotype, char *, size_t, void *);\fP\fICURLOPT_DEBUGFUNCTION\fP replaces the standard debug function used when\fICURLOPT_VERBOSE \fP is in effect. This callback receives debug information,as specified with the \fBcurl_infotype\fP argument. This function must return0. 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.IP CURLINFO_TEXTThe data is informational text..IP CURLINFO_HEADER_INThe data is header (or header-like) data received from the peer..IP CURLINFO_HEADER_OUTThe data is header (or header-like) data sent to the peer..IP CURLINFO_DATA_INThe data is protocol data received from the peer..IP CURLINFO_DATA_OUTThe data is protocol data sent to the peer..RE.IP CURLOPT_DEBUGDATAPass a pointer to whatever you want passed in to your\fICURLOPT_DEBUGFUNCTION\fP in the last void * argument. This pointer is notused by libcurl, it is only passed to the callback..IP CURLOPT_SSL_CTX_FUNCTIONFunction pointer that should match the following prototype: \fBCURLcodesslctxfun(CURL *curl, void *sslctx, void *parm);\fP This function gets calledby libcurl just before the initialization of an SSL connection after havingprocessed all other SSL related options to give a last chance to anapplication to modify the behaviour of openssl's ssl initialization. The\fIsslctx\fP parameter is actually a pointer to an openssl \fISSL_CTX\fP. Ifan error is returned no attempt to establish a connection is made and theperform operation will return the error code from this callback function. Setthe \fIparm\fP argument with the \fICURLOPT_SSL_CTX_DATA\fP option. Thisoption was introduced in 7.11.0.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -