📄 curl_easy_setopt.3
字号:
.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_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 the \fICURLOPT_POSTFIELDS\fP option to specify what data to post and\fICURLOPT_POSTFIELDSIZE\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 option.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 explictly set the new request type using\fICURLOPT_NOBODY\fP or \fICURLOPT_HTTPGET\fP or similar..IP CURLOPT_POSTFIELDSPass a char * 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.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.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.To make multipart/formdata posts (aka rfc1867-posts), check out the\fICURLOPT_HTTPPOST\fP option..IP CURLOPT_POSTFIELDSIZEIf you want to post data to the server without letting libcurl do a strlen()to measure the data size, this option must be used. When this option is usedyou can post fully binary data, which otherwise is likely to fail. If thissize is set to -1, the library will use strlen() to get the size..IP CURLOPT_POSTFIELDSIZE_LARGEPass a curl_off_t as parameter. Use this to set the size of the\fICURLOPT_POSTFIELDS\fP data to prevent libcurl from doing strlen() on thedata to figure out the size. This is the large file version of the\fICURLOPT_POSTFIELDSIZE\fP option. (Added in 7.11.1).IP CURLOPT_HTTPPOSTTells libcurl you want a multipart/formdata HTTP POST to be made and youinstruct what data to pass on to the server. Pass a pointer to a linked listof curl_httppost structs as parameter. . The easiest way to create such alist, is to use \fIcurl_formadd(3)\fP as documented. The data in this listmust remain intact until you close this curl handle again with\fIcurl_easy_cleanup(3)\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.When setting \fICURLOPT_HTTPPOST\fP, it will automatically set\fICURLOPT_NOBODY\fP to 0 (since 7.14.1)..IP CURLOPT_REFERERPass a pointer to a zero terminated string as parameter. It will be used toset the Referer: header in the http request sent to the remote server. Thiscan be used to fool servers or scripts. You can also set any custom headerwith \fICURLOPT_HTTPHEADER\fP..IP CURLOPT_USERAGENTPass a pointer to a zero terminated string as parameter. It will be used toset the User-Agent: header in the http request sent to the remote server. Thiscan be used to fool servers or scripts. You can also set any custom headerwith \fICURLOPT_HTTPHEADER\fP..IP CURLOPT_HTTPHEADERPass a pointer to a linked list of HTTP headers to pass to the server in yourHTTP request. The linked list should be a fully valid list of \fBstructcurl_slist\fP structs properly filled in. Use \fIcurl_slist_append(3)\fP tocreate the list and \fIcurl_slist_free_all(3)\fP to clean up an entirelist. If you add a header that is otherwise generated and used by libcurlinternally, your added one will be used instead. If you add a header with nocontents as in 'Accept:' (no data on the right side of the colon), theinternally used header will get disabled. Thus, using this option you can addnew headers, replace internal headers and remove internal headers. To add aheader with no contents, make the contents be two quotes: \&"". The headersincluded in the linked list must not be CRLF-terminated, because curl addsCRLF after each header item. Failure to comply with this will result instrange bugs because the server will most likely ignore part of the headersyou specified.The first line in a request (containing the method, usually a GET or POST) isnot a header and cannot be replaced using this option. Only the linesfollowing the request-line are headers. Adding this method line in this listof headers will only cause your request to send an invalid header.Pass a NULL to this to reset back to no custom headers.The most commonly replaced headers have "shortcuts" in the options\fICURLOPT_COOKIE\fP, \fICURLOPT_USERAGENT\fP and \fICURLOPT_REFERER\fP..IP CURLOPT_HTTP200ALIASESPass a pointer to a linked list of aliases to be treated as valid HTTP 200responses. Some servers respond with a custom header response line. Forexample, IceCast servers respond with "ICY 200 OK". By including this stringin your list of aliases, the response will be treated as a valid HTTP headerline such as "HTTP/1.0 200 OK". (Added in 7.10.3)The linked list should be a fully valid list of struct curl_slist structs, andbe properly filled in. Use \fIcurl_slist_append(3)\fP to create the list and\fIcurl_slist_free_all(3)\fP to clean up an entire list.The alias itself is not parsed for any version strings. So if your alias is\&"MYHTTP/9.9", Libcurl will not treat the server as responding with HTTPversion 9.9. Instead Libcurl will use the value set by option\fICURLOPT_HTTP_VERSION\fP..IP CURLOPT_COOKIEPass a pointer to a zero terminated string as parameter. It will be used toset a cookie in the http request. The format of the string should beNAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookieshould contain.If you need to set multiple cookies, you need to set them all using a singleoption and thus you need to concatenate them all in one single string. Setmultiple cookies in one string like this: "name1=content1; name2=content2;"etc.Using this option multiple times will only make the latest string override thepreviously ones..IP CURLOPT_COOKIEFILEPass a pointer to a zero terminated string as parameter. It should contain thename of your file holding cookie data to read. The cookie data may be inNetscape / Mozilla cookie data format or just regular HTTP-style headersdumped to a file.Given an empty or non-existing file or by passing the empty string (""), thisoption will enable cookies for this curl handle, making it understand andparse received cookies and then use matching cookies in future request.If you use this option multiple times, you just add more files to read.Subsequent files will add more cookies..IP CURLOPT_COOKIEJARPass a file name as char *, zero terminated. This will make libcurl write allinternally known cookies to the specified file when \fIcurl_easy_cleanup(3)\fPis called. If no cookies are known, no file will be created. Specify "-" toinstead have the cookies written to stdout. Using this option also enablescookies for this session, so if you for example follow a location it will makematching cookies get sent accordingly.If the cookie jar file can't be created or written to (when the\fIcurl_easy_cleanup(3)\fP is called), libcurl will not and cannot report anerror for this. Using \fICURLOPT_VERBOSE\fP or \fICURLOPT_DEBUGFUNCTION\fPwill get a warning to display, but that is the only visible feedback you getabout this possibly lethal situation..IP CURLOPT_COOKIESESSIONPass a long set to non-zero to mark this as a new cookie "session". It willforce libcurl to ignore all cookies it is about to load that are "sessioncookies" from the previous session. By default, libcurl always stores andloads all cookies, independent if they are session cookies are not. Sessioncookies are cookies without expiry date and they are meant to be alive and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -