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

📄 curl_easy_setopt.3

📁 功能最强大的网络爬虫,希望大家好好学习啊,好好研究啊
💻 3
📖 第 1 页 / 共 5 页
字号:
This function will get called on all new connections made to a server, duringthe SSL negotiation. The SSL_CTX pointer will be a new one every time.To use this properly, a non-trivial amount of knowledge of the openssllibraries is necessary. Using this function allows for example to use opensslcallbacks to add additional validation code for certificates, and even tochange the actual URI of an HTTPS request (example used in the lib509 testcase).  See also the example section for a replacement of the key, certificateand trust file settings..IP CURLOPT_SSL_CTX_DATAData pointer to pass to the ssl context callback set by the option\fICURLOPT_SSL_CTX_FUNCTION\fP, this is the pointer you'll get as thirdparameter, otherwise \fBNULL\fP. (Added in 7.11.0).IP CURLOPT_CONV_TO_NETWORK_FUNCTION.IP CURLOPT_CONV_FROM_NETWORK_FUNCTION.IP CURLOPT_CONV_FROM_UTF8_FUNCTIONFunction pointers that should match the following prototype: CURLcodefunction(char *ptr, size_t length);These three options apply to non-ASCII platforms only.  They are availableonly if \fBCURL_DOES_CONVERSIONS\fP was defined when libcurl was built. Whenthis is the case, \fIcurl_version_info(3)\fP will return the CURL_VERSION_CONVfeature bit set.The data to be converted is in a buffer pointed to by the ptr parameter.  Theamount of data to convert is indicated by the length parameter.  The converteddata overlays the input data in the buffer pointed to by the ptr parameter.CURLE_OK should be returned upon successful conversion.  A CURLcode returnvalue defined by curl.h, such as CURLE_CONV_FAILED, should be returned if anerror was encountered.\fBCURLOPT_CONV_TO_NETWORK_FUNCTION\fP and\fBCURLOPT_CONV_FROM_NETWORK_FUNCTION\fP convert between the host encoding andthe network encoding.  They are used when commands or ASCII data aresent/received over the network.\fBCURLOPT_CONV_FROM_UTF8_FUNCTION\fP is called to convert from UTF8 into thehost encoding.  It is required only for SSL processing.If you set a callback pointer to NULL, or don't set it at all, the built-inlibcurl iconv functions will be used.  If HAVE_ICONV was not defined whenlibcurl was built, and no callback has been established, conversion willreturn 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 asfollows: \&#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 yoursystem..SH ERROR OPTIONS.IP 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\fIcurl_easy_perform\fP. The buffer must be at least CURL_ERROR_SIZE big.Use \fICURLOPT_VERBOSE\fP and \fICURLOPT_DEBUGFUNCTION\fP to betterdebug/trace why errors happen.If the library does not return an error, the buffer may not have beentouched. Do not rely on the contents in those cases..IP CURLOPT_STDERRPass a FILE * as parameter. Tell libcurl to use this stream instead of stderrwhen showing the progress meter and displaying \fICURLOPT_VERBOSE\fP data..IP CURLOPT_FAILONERRORA non-zero parameter tells the library to fail silently if the HTTP codereturned is equal to or larger than 400. The default action would be to returnthe page normally, ignoring that code..SH NETWORK OPTIONS.IP 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.If the given URL lacks the protocol part ("http://" or "ftp://" etc), it willattempt to guess which protocol to use based on the given host name. If thegiven protocol of the set URL is not supported, libcurl will return on error(\fICURLE_UNSUPPORTED_PROTOCOL\fP) when you call \fIcurl_easy_perform(3)\fP or\fIcurl_multi_perform(3)\fP. Use \fIcurl_version_info(3)\fP for detailed infoon which protocols that are supported.The string given to CURLOPT_URL must be url-encoded and following the RFC 2396(http://curl.haxx.se/rfc/rfc2396.txt).\fICURLOPT_URL\fP is the only option that \fBmust\fP be set before\fIcurl_easy_perform(3)\fP is called..IP 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.When you tell the library to use an HTTP proxy, libcurl will transparentlyconvert operations to HTTP even if you specify an FTP URL etc. This may havean impact on what other features of the library you can use, such as\fICURLOPT_QUOTE\fP and similar FTP specifics that don't work unless youtunnel through the HTTP proxy. Such tunneling is activated with\fICURLOPT_HTTPPROXYTUNNEL\fP.libcurl respects the environment variables \fBhttp_proxy\fP, \fBftp_proxy\fP,\fBall_proxy\fP etc, if any of those is set. The \fICURLOPT_PROXY\fP optiondoes however override any possibly set environment variables.Starting with 7.14.1, the proxy host string can be specified the exact sameway as the proxy environment variables, include protocol prefix (http://) andembedded user + password..IP 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..IP CURLOPT_PROXYTYPEPass a long with this option to set type of the proxy. Available options forthis are \fICURLPROXY_HTTP\fP, \fICURLPROXY_SOCKS4\fP (added in 7.15.2)\fICURLPROXY_SOCKS5\fP. The HTTP type is default. (Added in 7.10).IP CURLOPT_HTTPPROXYTUNNELSet the parameter to non-zero to get the library to tunnel all operationsthrough a given HTTP proxy. There is a big difference between using a proxyand to tunnel through it. If you don't know what this means, you probablydon't want this tunneling option..IP 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..IP CURLOPT_LOCALPORTPass a long. This sets the local port number of the socket used forconnection. This can be used in combination with \fICURLOPT_INTERFACE\fP andyou are recommended to use \fICURLOPT_LOCALPORTRANGE\fP as well when this isset. Note that port numbers are only valid 1 - 65535. (Added in 7.15.2).IP CURLOPT_LOCALPORTRANGEPass a long. This is the number of attempts libcurl should do to find aworking local port number. It starts with the given \fICURLOPT_LOCALPORT\fPand adds one to the number for each retry. Setting this value to 1 or belowwill make libcurl do only one try for exact port number. Note that portnumbers by nature is a scarce resource that will be busy at times so settingthis value to something too low might cause unnecessary connection setupfailures. (Added in 7.15.2).IP 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 this info for 60 seconds..IP 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 variable.\fBWARNING:\fP this option is considered obsolete. Stop using it. Switch overto using the share interface instead! See \fICURLOPT_SHARE\fP and\fIcurl_share_init(3)\fP..IP CURLOPT_BUFFERSIZEPass a long specifying your preferred size (in bytes) for the receive bufferin libcurl.  The main point of this would be that the write callback getscalled 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. (Addedin 7.10)This size is by default set as big as possible (CURL_MAX_WRITE_SIZE), so itonly makse sense to use this option if you want it smaller..IP CURLOPT_PORTPass a long specifying what remote port number to connect to, instead of theone specified in the URL or the default port for the used protocol..IP CURLOPT_TCP_NODELAYPass a long specifying whether the TCP_NODELAY option should be set orcleared (1 = set, 0 = clear). The option is cleared by default. Thiswill have no effect after the connection has been established.Setting this option will disable TCP's Nagle algorithm. The purpose ofthis algorithm is to try to minimize the number of small packets onthe network (where "small packets" means TCP segments less than theMaximum Segment Size (MSS) for the network).Maximizing the amount of data sent per TCP segment is good because itamortizes the overhead of the send. However, in some cases (mostnotably telnet or rlogin) small segments may need to be sentwithout delay. This is less efficient than sending larger amounts ofdata at a time, and can contribute to congestion on the network ifoverdone..SH NAMES and PASSWORDS OPTIONS (Authentication).IP 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.libcurl uses a user name (and supplied or prompted password) supplied with\fICURLOPT_USERPWD\fP in preference to any of the options controlled by thisparameter.Pass a long, set to one of the values described below..RS.IP 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..IP CURL_NETRC_IGNOREDThe library will ignore the file and use only the information in the URL.This is the default..IP 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..REOnly machine name, user name and password are taken into account(init macros and similar things aren't supported).libcurl does not verify that the file has the correct properties set (as thestandard Unix ftp client does). It should only be readable by user..IP CURLOPT_NETRC_FILEPass a char * as parameter, pointing to a zero terminated string containingthe full path name to the file you want libcurl to use as .netrc file. If thisoption is omitted, and \fICURLOPT_NETRC\fP is set, libcurl will attempt tofind the a .netrc file in the current user's home directory. (Added in 7.10.9).IP CURLOPT_USERPWDPass a char * as parameter, which should be [user name]:[password] to use forthe connection. Use \fICURLOPT_HTTPAUTH\fP to decide authentication method.When using NTLM, you can set domain by prepending it to the user name andseparating the domain and name with a forward (/) or backward slash (\\). Likethis: "domain/user:password" or "domain\\user:password". Some HTTP servers (onWindows) support this style even for Basic authentication.When using HTTP and \fICURLOPT_FOLLOWLOCATION\fP, libcurl might performseveral requests to possibly different hosts. libcurl will only send this userand password information to hosts using the initial host name (unless\fICURLOPT_UNRESTRICTED_AUTH\fP is set), so if libcurl follows locations toother hosts it will not send the user and password to those. This is enforcedto prevent accidental information leakage..IP CURLOPT_PROXYUSERPWDPass a char * as parameter, which should be [user name]:[password] to use forthe connection to the HTTP proxy.  Use \fICURLOPT_PROXYAUTH\fP to decideauthentication method..IP CURLOPT_HTTPAUTHPass a long as parameter, which is set to a bitmask, to tell libcurl whatauthentication method(s) you want it to use. The available bits are listedbelow. If more than one bit is set, libcurl will first query the site to seewhat authentication methods it supports and then pick the best one you allowit to use. For some methods, this will induce an extra network round-trip. Setthe actual name and password with the \fICURLOPT_USERPWD\fP option. (Added in7.10.6)

⌨️ 快捷键说明

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