⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curl_easy_setopt.3

📁 THIS IS HTTP CURL Example
💻 3
📖 第 1 页 / 共 5 页
字号:
.\" **************************************************************************.\" *                                  _   _ ____  _.\" *  Project                     ___| | | |  _ \| |.\" *                             / __| | | | |_) | |.\" *                            | (__| |_| |  _ <| |___.\" *                             \___|\___/|_| \_\_____|.\" *.\" * Copyright (C) 1998 - 2008, 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.211 2008-01-11 14:20:41 bagder Exp $.\" **************************************************************************.\".TH curl_easy_setopt 3 "5 Jan 2008" "libcurl 7.18.0" "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, are copied by the library;thus the string storage associated to the pointer argument may be overwrittenafter curl_easy_setopt() returns. Exceptions to this rule are described inthe option details below.NOTE: before 7.17.0 strings were not copied. Instead the user was forced keepthem available until libcurl no longer needed them.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.From 7.18.0, the function can return CURL_WRITEFUNC_PAUSE which then willcause writing to this connection to become paused. See\fIcurl_easy_pause(3)\fP for further details.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)From 7.18.0, the function can return CURL_READFUNC_PAUSE which then will causereading from this connection to become paused. See \fIcurl_easy_pause(3)\fPfor further details.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.  (Option added in7.12.3).Use \fICURLOPT_SEEKFUNCTION\fP instead to provide seeking!.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_SEEKFUNCTIONFunction pointer that should match the following prototype: \fIintfunction(void *instream, curl_off_t offset, int origin);\fP This function getscalled by libcurl to seek to a certain position in the input stream and can beused to fast forward a file in a resumed upload (instead of reading alluploaded bytes with the normal read function/callback). It is also called torewind a stream when doing a HTTP PUT or POST with a multi-pass authenticationmethod. The function shall work like "fseek" or "lseek" and accepted SEEK_SET,SEEK_CUR and SEEK_END as argument for origin, although (in 7.18.0) libcurlonly passes SEEK_SET. The callback must return 0 on success as returningnon-zero will cause the upload operation to fail.If you forward the input arguments directly to "fseek" or "lseek", note thatthe data type for \fIoffset\fP is not the same as defined for curl_off_t onmany systems! (Option added in 7.18.0).IP CURLOPT_SEEKDATAData pointer to pass to the file read function. If you use the\fICURLOPT_SEEKFUNCTION\fP option, this is the pointer you'll get as input. Ifyou don't specify a seek callback, NULL is passed. (Option added in 7.18.0).IP CURLOPT_SOCKOPTFUNCTIONFunction pointer that should match the \fIcurl_sockopt_callback\fP prototypefound in \fI<curl/curl.h>\fP. This function gets called by libcurl after thesocket() call but before the connect() call. The callback's \fIpurpose\fPargument identifies the exact purpose for this particular socket, andcurrently only one value is supported: \fICURLSOCKTYPE_IPCXN\fP for theprimary connection (meaning the control connection in the FTP case). Futureversions of libcurl may support more purposes. It passes the newly createdsocket descriptor so additional setsockopt() calls can be done at the user'sdiscretion.  A non-zero return code from the callback function will signal anunrecoverable error to the library and it will close the socket and return\fICURLE_COULDNT_CONNECT\fP.  (Option added in 7.15.6.).IP CURLOPT_SOCKOPTDATAPass a pointer that will be untouched by libcurl and passed as the firstargument in the sockopt callback set with \fICURLOPT_SOCKOPTFUNCTION\fP.(Option added in 7.15.6.).IP CURLOPT_OPENSOCKETFUNCTIONFunction pointer that should match the \fIcurl_opensocket_callback\fPprototype found in \fI<curl/curl.h>\fP. This function gets called by libcurlinstead of the \fIsocket(2)\fP call. The callback's \fIpurpose\fP argumentidentifies the exact purpose for this particular socket, and currently onlyone value is supported: \fICURLSOCKTYPE_IPCXN\fP for the primary connection(meaning the control connection in the FTP case). Future versions of libcurlmay support more purposes. It passes the resolved peer address as a\fIaddress\fP argument so the callback can modify the address or refuse toconnect at all. The callback function should return the socket or\fICURL_SOCKET_BAD\fP in case no connection should be established or any errordetected. Any additional \fIsetsockopt(2)\fP calls can be done on the socketat the user's discretion.  \fICURL_SOCKET_BAD\fP return value from thecallback function will signal an unrecoverable error to the library and itwill return \fICURLE_COULDNT_CONNECT\fP.  This return code can be used for IPaddress blacklisting.  The default behavior is:.Bd -literal -offset indent   return socket(addr->family, addr->socktype, addr->protocol);.Ed(Option added in 7.17.1.).IP CURLOPT_OPENSOCKETDATAPass a pointer that will be untouched by libcurl and passed as the firstargument in the opensocket callback set with \fICURLOPT_OPENSOCKETFUNCTION\fP.(Option added in 7.17.1.).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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -