📄 curl_easy_setopt.3
字号:
.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 makes 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).RS.IP CURLAUTH_BASICHTTP Basic authentication. This is the default choice, and the only methodthat is in wide-spread use and supported virtually everywhere. This is sendingthe user name and password over the network in plain text, easily captured byothers..IP CURLAUTH_DIGESTHTTP Digest authentication. Digest authentication is defined in RFC2617 andis a more secure way to do authentication over public networks than theregular old-fashioned Basic method..IP CURLAUTH_GSSNEGOTIATEHTTP GSS-Negotiate authentication. The GSS-Negotiate (also known as plain\&"Negotiate") method was designed by Microsoft and is used in their webapplications. It is primarily meant as a support for Kerberos5 authenticationbut may be also used along with another authentication methods. For moreinformation see IETF draft draft-brezak-spnego-http-04.txt.You need to build libcurl with a suitable GSS-API library for this to work..IP CURLAUTH_NTLMHTTP NTLM authentication. A proprietary protocol invented and used byMicrosoft. It uses a challenge-response and hash concept similar to Digest, toprevent the password from being eavesdropped.You need to build libcurl with OpenSSL support for this option to work, orbuild libcurl on Windows..IP CURLAUTH_ANYThis is a convenience macro that sets all bits and thus makes libcurl pick anyit finds suitable. libcurl will automatically select the one it finds mostsecure..IP CURLAUTH_ANYSAFEThis is a convenience macro that sets all bits except Basic and thus makeslibcurl pick any it finds suitable. libcurl will automatically select the one itfinds most secure..RE.IP CURLOPT_PROXYAUTHPass a long as parameter, which is set to a bitmask, to tell libcurl whatauthentication method(s) you want it to use for your proxy authentication. Ifmore than one bit is set, libcurl will first query the site to see whatauthentication methods it supports and then pick the best one you allow it touse. For some methods, this will induce an extra network round-trip. Set theactual name and password with the \fICURLOPT_PROXYUSERPWD\fP option. Thebitmask can be constructed by or'ing together the bits listed above for the\fICURLOPT_HTTPAUTH\fP option. As of this writing, only Basic, Digest and NTLMwork. (Added in 7.10.7).SH HTTP OPTIONS.IP CURLOPT_AUTOREFERERPass a non-zero parameter to enable this. When enabled, libcurl willautomatically set the Referer: field in requests where it follows a Location:redirect..IP CURLOPT_ENCODINGSets the contents of the Accept-Encoding: header sent in an HTTPrequest, and enables decoding of a response when a Content-Encoding:header is received. Three encodings are supported: \fIidentity\fP,which does nothing, \fIdeflate\fP which requests the server tocompress its response using the zlib algorithm, and \fIgzip\fP whichrequests the gzip algorithm. If a zero-length string is set, then anAccept-Encoding: header containing all supported encodings is sent.This is a request, not an order; the server may or may not do it. Thisoption must be set (to any non-NULL value) or else any unsolicitedencoding done by the server is ignored. See the special filelib/README.encoding for details..IP CURLOPT_FOLLOWLOCATIONA non-zero parameter tells the library to follow any Location: header that theserver sends as part of an HTTP header.This means that the library will re-send the same request on the new locationand follow new Location: headers all the way until no more such headers arereturned. \fICURLOPT_MAXREDIRS\fP can be used to limit the number of redirectslibcurl will follow..IP CURLOPT_UNRESTRICTED_AUTHA non-zero parameter tells the library it can continue to send authentication(user+password) when following locations, even when hostname changed. Thisoption is meaningful only when setting \fICURLOPT_FOLLOWLOCATION\fP..IP CURLOPT_MAXREDIRSPass a long. The set number will be the redirection limit. If that manyredirections have been followed, the next redirect will cause an error(\fICURLE_TOO_MANY_REDIRECTS\fP). This option only makes sense if the\fICURLOPT_FOLLOWLOCATION\fP is used at the same time. Added in 7.15.1:Setting the limit to 0 will make libcurl refuse any redirect. Set it to -1 foran infinite number of redirects (which is the default).IP CURLOPT_POST301A non-zero parameter tells the library to respect RFC 2616/10.3.2 and notconvert POST requests into GET requests when following a 301 redirection. Thenon-RFC behaviour is ubiquitous in web browsers, so the library does theconversion by default to maintain consistency. However, a server may requiresa POST to remain a POST after such a redirection. This option is meaningfulonly when setting \fICURLOPT_FOLLOWLOCATION\fP. (Added in 7.17.1).IP CURLOPT_PUTA non-zero parameter tells the library to use HTTP PUT to transfer data. Thedata should be set with \fICURLOPT_READDATA\fP and \fICURLOPT_INFILESIZE\fP.This option is deprecated and starting with version 7.12.1 you should insteaduse \fICURLOPT_UPLOAD\fP..IP CURLOPT_POSTA non-zero parameter tells the library to do a regular HTTP post. This willalso make the library use the a "Content-Type:application/x-www-form-urlencoded" header. (This is by far the most commonlyused POST method).Use one of \fICURLOPT_POSTFIELDS\fP or \fICURLOPT_COPYPOSTFIELDS\fP options tospecify what data to post and \fICURLOPT_POSTFIELDSIZE\fP or\fICURLOPT_POSTFIELDSIZE_LARGE\fP to set the data size.Optionally, you can provide data to POST using the \fICURLOPT_READFUNCTION\fPand \fICURLOPT_READDATA\fP options but then you must make sure to not set\fICURLOPT_POSTFIELDS\fP to anything but NULL. When providing data with acallback, you must transmit it using chunked transfer-encoding or you must setthe size of the data with the \fICURLOPT_POSTFIELDSIZE\fP or\fICURLOPT_POSTFIELDSIZE_LARGE\fP option. To enable chunked encoding, yousimply pass in the appropriate Transfer-Encoding header, see thepost-callback.c example.You can override the default POST Content-Type: header by setting your ownwith \fICURLOPT_HTTPHEADER\fP.Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header.You can disable this header with \fICURLOPT_HTTPHEADER\fP as usual.If you use POST to a HTTP 1.1 server, you can send data without knowing thesize before starting the POST if you use chunked encoding. You enable this byadding a header like "Transfer-Encoding: chunked" with\fICURLOPT_HTTPHEADER\fP. With HTTP 1.0 or without chunked transfer, you mustspecify the size in the request.When setting \fICURLOPT_POST\fP to a non-zero value, it will automatically set\fICURLOPT_NOBODY\fP to 0 (since 7.14.1).If you issue a POST request and then want to make a HEAD or GET using the samere-used handle, you must explicitly set the new request type using\fICURLOPT_NOBODY\fP or \fICURLOPT_HTTPGET\fP or similar..IP CURLOPT_POSTFIELDSPass a void * as parameter, which should be the full data to post in an HTTPPOST operation. You must make sure that the data is formatted the way you wantthe server to receive it. libcurl will not convert or encode it for you. Mostweb servers will assume this data to be url-encoded. Take note.The pointed data are NOT copied by the library: as a consequence, they mustbe preserved by the calling application until the transfer finishes.This POST is a normal application/x-www-form-urlencoded kind (and libcurl willset that Content-Type by default when this option is used), which is the mostcommonly used one by HTML forms. See also the \fICURLOPT_POST\fP. Using\fICURLOPT_POSTFIELDS\fP implies \fICURLOPT_POST\fP.If you want to do a zero-byte POST, you need to set\fICURLOPT_POSTFIELDSIZE\fP explicitly to zero, as simply setting
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -