libcurl curl_easy_setopt函数以及设置选项

NAME

curl_easy_setopt - set options for a curl easy handle

SYNOPSIS

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter);

DESCRIPTION

curl_easy_setopt is used to tell libcurl how to behave. By setting the appropriate options, the application can change libcurl's behavior. All options are set with an option followed by a parameter. That parameter can be a long, a function pointer, an object pointer or a curl_off_t, depending on what the specific option expects. Read this manual carefully as bad input values may cause libcurl to behave badly! You can only set one option in each function call. A typical application uses many curl_easy_setopt calls in the setup phase.

Options set with this function call are valid for all forthcoming transfers performed using this handle. The options are not in any way reset between transfers, so if you want subsequent transfers with different options, you must change them between the transfers. You can optionally reset all options back to internal default with curl_easy_reset.

Strings passed to libcurl as 'char *' arguments, are copied by the library; thus the string storage associated to the pointer argument may be overwritten after curl_easy_setopt returns. The only exception to this rule is really CURLOPT_POSTFIELDS, but the alternative that copies the string CURLOPT_COPYPOSTFIELDShas some usage characteristics you need to read up on.

The order in which the options are set does not matter.

Before version 7.17.0, strings were not copied. Instead the user was forced keep them available until libcurl no longer needed them.

The handle is the return code from a curl_easy_init or curl_easy_duphandle call.

BEHAVIOR OPTIONS

CURLOPT_VERBOSE

Display verbose information. See CURLOPT_VERBOSE

CURLOPT_HEADER

Include the header in the body output. See CURLOPT_HEADER

CURLOPT_NOPROGRESS

Shut off the progress meter. See CURLOPT_NOPROGRESS

CURLOPT_NOSIGNAL

Do not install signal handlers. See CURLOPT_NOSIGNAL

CURLOPT_WILDCARDMATCH

Transfer multiple files according to a file name pattern. See CURLOPT_WILDCARDMATCH

CALLBACK OPTIONS

CURLOPT_WRITEFUNCTION

Callback for writing data. See CURLOPT_WRITEFUNCTION

CURLOPT_WRITEDATA

Data pointer to pass to the write callback. See CURLOPT_WRITEDATA

CURLOPT_READFUNCTION

Callback for reading data. See CURLOPT_READFUNCTION

CURLOPT_READDATA

Data pointer to pass to the read callback. See CURLOPT_READDATA

CURLOPT_IOCTLFUNCTION

Callback for I/O operations. See CURLOPT_IOCTLFUNCTION

CURLOPT_IOCTLDATA

Data pointer to pass to the I/O callback. See CURLOPT_IOCTLDATA

CURLOPT_SEEKFUNCTION

Callback for seek operations. See CURLOPT_SEEKFUNCTION

CURLOPT_SEEKDATA

Data pointer to pass to the seek callback. See CURLOPT_SEEKDATA

CURLOPT_SOCKOPTFUNCTION

Callback for sockopt operations. See CURLOPT_SOCKOPTFUNCTION

CURLOPT_SOCKOPTDATA

Data pointer to pass to the sockopt callback. See CURLOPT_SOCKOPTDATA

CURLOPT_OPENSOCKETFUNCTION

Callback for socket creation. See CURLOPT_OPENSOCKETFUNCTION

CURLOPT_OPENSOCKETDATA

Data pointer to pass to the open socket callback. See CURLOPT_OPENSOCKETDATA

CURLOPT_CLOSESOCKETFUNCTION

Callback for closing socket. See CURLOPT_CLOSESOCKETFUNCTION

CURLOPT_CLOSESOCKETDATA

Data pointer to pass to the close socket callback. See CURLOPT_CLOSESOCKETDATA

CURLOPT_PROGRESSFUNCTION

OBSOLETE callback for progress meter. See CURLOPT_PROGRESSFUNCTION

CURLOPT_PROGRESSDATA

Data pointer to pass to the progress meter callback. See CURLOPT_PROGRESSDATA

CURLOPT_XFERINFOFUNCTION

Callback for progress meter. See CURLOPT_XFERINFOFUNCTION

CURLOPT_XFERINFODATA

Data pointer to pass to the progress meter callback. See CURLOPT_XFERINFODATA

CURLOPT_HEADERFUNCTION

Callback for writing received headers. See CURLOPT_HEADERFUNCTION

CURLOPT_HEADERDATA

Data pointer to pass to the header callback. See CURLOPT_HEADERDATA

CURLOPT_DEBUGFUNCTION

Callback for debug information. See CURLOPT_DEBUGFUNCTION

CURLOPT_DEBUGDATA

Data pointer to pass to the debug callback. See CURLOPT_DEBUGDATA

CURLOPT_SSL_CTX_FUNCTION

Callback for SSL context logic. See CURLOPT_SSL_CTX_FUNCTION

CURLOPT_SSL_CTX_DATA

Data pointer to pass to the SSL context callback. See CURLOPT_SSL_CTX_DATA

CURLOPT_CONV_TO_NETWORK_FUNCTION

Callback for code base conversion. See CURLOPT_CONV_TO_NETWORK_FUNCTION

CURLOPT_CONV_FROM_NETWORK_FUNCTION

Callback for code base conversion. See CURLOPT_CONV_FROM_NETWORK_FUNCTION

CURLOPT_CONV_FROM_UTF8_FUNCTION

Callback for code base conversion. See CURLOPT_CONV_FROM_UTF8_FUNCTION

CURLOPT_INTERLEAVEFUNCTION

Callback for RTSP interleaved data. See CURLOPT_INTERLEAVEFUNCTION

CURLOPT_INTERLEAVEDATA

Data pointer to pass to the RTSP interleave callback. See CURLOPT_INTERLEAVEDATA

CURLOPT_CHUNK_BGN_FUNCTION

Callback for wildcard download start of chunk. See CURLOPT_CHUNK_BGN_FUNCTION

CURLOPT_CHUNK_END_FUNCTION

Callback for wildcard download end of chunk. See CURLOPT_CHUNK_END_FUNCTION

CURLOPT_CHUNK_DATA

Data pointer to pass to the chunk callbacks. See CURLOPT_CHUNK_DATA

CURLOPT_FNMATCH_FUNCTION

Callback for wildcard matching. See CURLOPT_FNMATCH_FUNCTION

CURLOPT_FNMATCH_DATA

Data pointer to pass to the wildcard matching callback. See CURLOPT_FNMATCH_DATA

ERROR OPTIONS

CURLOPT_ERRORBUFFER

Error message buffer. See CURLOPT_ERRORBUFFER

CURLOPT_STDERR

stderr replacement stream. See CURLOPT_STDERR

CURLOPT_FAILONERROR

Fail on HTTP 4xx errors. CURLOPT_FAILONERROR

NETWORK OPTIONS

CURLOPT_URL

URL to work on. See CURLOPT_URL

CURLOPT_PATH_AS_IS

Disable squashing /../ and /./ sequences in the path. See CURLOPT_PATH_AS_IS

CURLOPT_PROTOCOLS

Allowed protocols. See CURLOPT_PROTOCOLS

CURLOPT_REDIR_PROTOCOLS

Protocols to allow redirects to. See CURLOPT_REDIR_PROTOCOLS

CURLOPT_DEFAULT_PROTOCOL

Default protocol. See CURLOPT_DEFAULT_PROTOCOL

CURLOPT_PROXY

Proxy to use. See CURLOPT_PROXY

CURLOPT_PROXYPORT

Proxy port to use. See CURLOPT_PROXYPORT

CURLOPT_PROXYTYPE

Proxy type. See CURLOPT_PROXYTYPE

CURLOPT_NOPROXY

Filter out hosts from proxy use. CURLOPT_NOPROXY

CURLOPT_HTTPPROXYTUNNEL

Tunnel through the HTTP proxy. CURLOPT_HTTPPROXYTUNNEL

CURLOPT_SOCKS5_GSSAPI_SERVICE

Socks5 GSSAPI service name. CURLOPT_SOCKS5_GSSAPI_SERVICE

CURLOPT_SOCKS5_GSSAPI_NEC

Socks5 GSSAPI NEC mode. See CURLOPT_SOCKS5_GSSAPI_NEC

CURLOPT_PROXY_SERVICE_NAME

Proxy service name. CURLOPT_PROXY_SERVICE_NAME

CURLOPT_SERVICE_NAME

SPNEGO service name. CURLOPT_SERVICE_NAME

CURLOPT_INTERFACE

Bind connection locally to this. See CURLOPT_INTERFACE

CURLOPT_LOCALPORT

Bind connection locally to this port. See CURLOPT_LOCALPORT

CURLOPT_LOCALPORTRANGE

Bind connection locally to port range. See CURLOPT_LOCALPORTRANGE

CURLOPT_DNS_CACHE_TIMEOUT

Timeout for DNS cache. See CURLOPT_DNS_CACHE_TIMEOUT

CURLOPT_DNS_USE_GLOBAL_CACHE

OBSOLETE Enable global DNS cache. See CURLOPT_DNS_USE_GLOBAL_CACHE

CURLOPT_BUFFERSIZE

Ask for smaller buffer size. See CURLOPT_BUFFERSIZE

CURLOPT_PORT

Port number to connect to. See CURLOPT_PORT

CURLOPT_TCP_NODELAY

Disable the Nagle algorithm. See CURLOPT_TCP_NODELAY

CURLOPT_ADDRESS_SCOPE

IPv6 scope for local addresses. See CURLOPT_ADDRESS_SCOPE

CURLOPT_TCP_KEEPALIVE

Enable TCP keep-alive. See CURLOPT_TCP_KEEPALIVE

CURLOPT_TCP_KEEPIDLE

Idle time before sending keep-alive. See CURLOPT_TCP_KEEPIDLE

CURLOPT_TCP_KEEPINTVL

Interval between keep-alive probes. See CURLOPT_TCP_KEEPINTVL

CURLOPT_UNIX_SOCKET_PATH

Path to a Unix domain socket. See CURLOPT_UNIX_SOCKET_PATH

NAMES and PASSWORDS OPTIONS (Authentication)

CURLOPT_NETRC

Enable .netrc parsing. See CURLOPT_NETRC

CURLOPT_NETRC_FILE

.netrc file name. See CURLOPT_NETRC_FILE

CURLOPT_USERPWD

User name and password. See CURLOPT_USERPWD

CURLOPT_PROXYUSERPWD

Proxy user name and password. See CURLOPT_PROXYUSERPWD

CURLOPT_USERNAME

User name. See CURLOPT_USERNAME

CURLOPT_PASSWORD

Password. See CURLOPT_PASSWORD

CURLOPT_LOGIN_OPTIONS

Login options. See CURLOPT_LOGIN_OPTIONS

CURLOPT_PROXYUSERNAME

Proxy user name. See CURLOPT_PROXYUSERNAME

CURLOPT_PROXYPASSWORD

Proxy password. See CURLOPT_PROXYPASSWORD

CURLOPT_HTTPAUTH

HTTP server authentication methods. See CURLOPT_HTTPAUTH

CURLOPT_TLSAUTH_USERNAME

TLS authentication user name. See CURLOPT_TLSAUTH_USERNAME

CURLOPT_TLSAUTH_PASSWORD

TLS authentication password. See CURLOPT_TLSAUTH_PASSWORD

CURLOPT_TLSAUTH_TYPE

TLS authentication methods. See CURLOPT_TLSAUTH_TYPE

CURLOPT_PROXYAUTH

HTTP proxy authentication methods. See CURLOPT_PROXYAUTH

CURLOPT_SASL_IR

Enable SASL initial response. See CURLOPT_SASL_IR

CURLOPT_XOAUTH2_BEARER

OAuth2 bearer token. See CURLOPT_XOAUTH2_BEARER

HTTP OPTIONS

CURLOPT_AUTOREFERER

Automatically set Referer: header. See CURLOPT_AUTOREFERER

CURLOPT_ACCEPT_ENCODING

Accept-Encoding and automatic decompressing data. See CURLOPT_ACCEPT_ENCODING

CURLOPT_TRANSFER_ENCODING

Request Transfer-Encoding. See CURLOPT_TRANSFER_ENCODING

CURLOPT_FOLLOWLOCATION

Follow HTTP redirects. See CURLOPT_FOLLOWLOCATION

CURLOPT_UNRESTRICTED_AUTH

Do not restrict authentication to original host. CURLOPT_UNRESTRICTED_AUTH

CURLOPT_MAXREDIRS

Maximum number of redirects to follow. See CURLOPT_MAXREDIRS

CURLOPT_POSTREDIR

How to act on redirects after POST. See CURLOPT_POSTREDIR

CURLOPT_PUT

Issue a HTTP PUT request. See CURLOPT_PUT

CURLOPT_POST

Issue a HTTP POST request. See CURLOPT_POST

CURLOPT_POSTFIELDS

Send a POST with this data. See CURLOPT_POSTFIELDS

CURLOPT_POSTFIELDSIZE

The POST data is this big. See CURLOPT_POSTFIELDSIZE

CURLOPT_POSTFIELDSIZE_LARGE

The POST data is this big. See CURLOPT_POSTFIELDSIZE_LARGE

CURLOPT_COPYPOSTFIELDS

Send a POST with this data - and copy it. See CURLOPT_COPYPOSTFIELDS

CURLOPT_HTTPPOST

Multipart formpost HTTP POST. See CURLOPT_HTTPPOST

CURLOPT_REFERER

Referer: header. See CURLOPT_REFERER

CURLOPT_USERAGENT

User-Agent: header. See CURLOPT_USERAGENT

CURLOPT_HTTPHEADER

Custom HTTP headers. See CURLOPT_HTTPHEADER

CURLOPT_HEADEROPT

Control custom headers. See CURLOPT_HEADEROPT

CURLOPT_PROXYHEADER

Custom HTTP headers sent to proxy. See CURLOPT_PROXYHEADER

CURLOPT_HTTP200ALIASES

Alternative versions of 200 OK. See CURLOPT_HTTP200ALIASES

CURLOPT_COOKIE

Cookie(s) to send. See CURLOPT_COOKIE

CURLOPT_COOKIEFILE

File to read cookies from. See CURLOPT_COOKIEFILE

CURLOPT_COOKIEJAR

File to write cookies to. See CURLOPT_COOKIEJAR

CURLOPT_COOKIESESSION

Start a new cookie session. See CURLOPT_COOKIESESSION

CURLOPT_COOKIELIST

Add or control cookies. See CURLOPT_COOKIELIST

CURLOPT_HTTPGET

Do a HTTP GET request. See CURLOPT_HTTPGET

CURLOPT_HTTP_VERSION

HTTP version to use. CURLOPT_HTTP_VERSION

CURLOPT_IGNORE_CONTENT_LENGTH

Ignore Content-Length. See CURLOPT_IGNORE_CONTENT_LENGTH

CURLOPT_HTTP_CONTENT_DECODING

Disable Content decoding. See CURLOPT_HTTP_CONTENT_DECODING

CURLOPT_HTTP_TRANSFER_DECODING

Disable Transfer decoding. See CURLOPT_HTTP_TRANSFER_DECODING

CURLOPT_EXPECT_100_TIMEOUT_MS

100-continue timeout. See CURLOPT_EXPECT_100_TIMEOUT_MS

CURLOPT_PIPEWAIT

Wait on connection to pipeline on it. See CURLOPT_PIPEWAIT

SMTP OPTIONS

CURLOPT_MAIL_FROM

Address of the sender. See CURLOPT_MAIL_FROM

CURLOPT_MAIL_RCPT

Address of the recipients. See CURLOPT_MAIL_RCPT

CURLOPT_MAIL_AUTH

Authentication address. See CURLOPT_MAIL_AUTH

TFTP OPTIONS

CURLOPT_TFTP_BLKSIZE

TFTP block size. See CURLOPT_TFTP_BLKSIZE

FTP OPTIONS

CURLOPT_FTPPORT

Use active FTP. See CURLOPT_FTPPORT

CURLOPT_QUOTE

Commands to run before transfer. See CURLOPT_QUOTE

CURLOPT_POSTQUOTE

Commands to run after transfer. See CURLOPT_POSTQUOTE

CURLOPT_PREQUOTE

Commands to run just before transfer. See CURLOPT_PREQUOTE

CURLOPT_APPEND

Append to remote file. See CURLOPT_APPEND

CURLOPT_FTP_USE_EPRT

Use EPTR. See CURLOPT_FTP_USE_EPRT

CURLOPT_FTP_USE_EPSV

Use EPSV. See CURLOPT_FTP_USE_EPSV

CURLOPT_FTP_USE_PRET

Use PRET. See CURLOPT_FTP_USE_PRET

CURLOPT_FTP_CREATE_MISSING_DIRS

Create missing directories on the remote server. See CURLOPT_FTP_CREATE_MISSING_DIRS

CURLOPT_FTP_RESPONSE_TIMEOUT

Timeout for FTP responses. See CURLOPT_FTP_RESPONSE_TIMEOUT

CURLOPT_FTP_ALTERNATIVE_TO_USER

Alternative to USER. See CURLOPT_FTP_ALTERNATIVE_TO_USER

CURLOPT_FTP_SKIP_PASV_IP

Ignore the IP address in the PASV response. See CURLOPT_FTP_SKIP_PASV_IP

CURLOPT_FTPSSLAUTH

Control how to do TLS. See CURLOPT_FTPSSLAUTH

CURLOPT_FTP_SSL_CCC

Back to non-TLS again after authentication. See CURLOPT_FTP_SSL_CCC

CURLOPT_FTP_ACCOUNT

Send ACCT command. See CURLOPT_FTP_ACCOUNT

CURLOPT_FTP_FILEMETHOD

Specify how to reach files. See CURLOPT_FTP_FILEMETHOD

RTSP OPTIONS

CURLOPT_RTSP_REQUEST

RTSP request. See CURLOPT_RTSP_REQUEST

CURLOPT_RTSP_SESSION_ID

RTSP session-id. See CURLOPT_RTSP_SESSION_ID

CURLOPT_RTSP_STREAM_URI

RTSP stream URI. See CURLOPT_RTSP_STREAM_URI

CURLOPT_RTSP_TRANSPORT

RTSP Transport: header. See CURLOPT_RTSP_TRANSPORT

CURLOPT_RTSP_CLIENT_CSEQ

Client CSEQ number. See CURLOPT_RTSP_CLIENT_CSEQ

CURLOPT_RTSP_SERVER_CSEQ

CSEQ number for RTSP Server->Client request. See CURLOPT_RTSP_SERVER_CSEQ

PROTOCOL OPTIONS

CURLOPT_TRANSFERTEXT

Use text transfer. See CURLOPT_TRANSFERTEXT

CURLOPT_PROXY_TRANSFER_MODE

Add transfer mode to URL over proxy. See CURLOPT_PROXY_TRANSFER_MODE

CURLOPT_CRLF

Convert newlines. See CURLOPT_CRLF

CURLOPT_RANGE

Range requests. See CURLOPT_RANGE

CURLOPT_RESUME_FROM

Resume a transfer. See CURLOPT_RESUME_FROM

CURLOPT_RESUME_FROM_LARGE

Resume a transfer. See CURLOPT_RESUME_FROM_LARGE

CURLOPT_CUSTOMREQUEST

Custom request/method. See CURLOPT_CUSTOMREQUEST

CURLOPT_FILETIME

Request file modification date and time. See CURLOPT_FILETIME

CURLOPT_DIRLISTONLY

List only. See CURLOPT_DIRLISTONLY

CURLOPT_NOBODY

Do not get the body contents. See CURLOPT_NOBODY

CURLOPT_INFILESIZE

Size of file to send. CURLOPT_INFILESIZE

CURLOPT_INFILESIZE_LARGE

Size of file to send. CURLOPT_INFILESIZE_LARGE

CURLOPT_UPLOAD

Upload data. See CURLOPT_UPLOAD

CURLOPT_MAXFILESIZE

Maximum file size to get. See CURLOPT_MAXFILESIZE

CURLOPT_MAXFILESIZE_LARGE

Maximum file size to get. See CURLOPT_MAXFILESIZE_LARGE

CURLOPT_TIMECONDITION

Make a time conditional request. See CURLOPT_TIMECONDITION

CURLOPT_TIMEVALUE

Time value for the time conditional request. See CURLOPT_TIMEVALUE

CONNECTION OPTIONS

CURLOPT_TIMEOUT

Timeout for the entire request. See CURLOPT_TIMEOUT

CURLOPT_TIMEOUT_MS

Millisecond timeout for the entire request. See CURLOPT_TIMEOUT_MS

CURLOPT_LOW_SPEED_LIMIT

Low speed limit to abort transfer. See CURLOPT_LOW_SPEED_LIMIT

CURLOPT_LOW_SPEED_TIME

Time to be below the speed to trigger low speed abort. See CURLOPT_LOW_SPEED_TIME

CURLOPT_MAX_SEND_SPEED_LARGE

Cap the upload speed to this. See CURLOPT_MAX_SEND_SPEED_LARGE

CURLOPT_MAX_RECV_SPEED_LARGE

Cap the download speed to this. See CURLOPT_MAX_RECV_SPEED_LARGE

CURLOPT_MAXCONNECTS

Maximum number of connections in the connection pool. See CURLOPT_MAXCONNECTS

CURLOPT_FRESH_CONNECT

Use a new connection. CURLOPT_FRESH_CONNECT

CURLOPT_FORBID_REUSE

Prevent subsequent connections from re-using this. See CURLOPT_FORBID_REUSE

CURLOPT_CONNECTTIMEOUT

Timeout for the connection phase. See CURLOPT_CONNECTTIMEOUT

CURLOPT_CONNECTTIMEOUT_MS

Millisecond timeout for the connection phase. See CURLOPT_CONNECTTIMEOUT_MS

CURLOPT_IPRESOLVE

IP version to resolve to. See CURLOPT_IPRESOLVE

CURLOPT_CONNECT_ONLY

Only connect, nothing else. See CURLOPT_CONNECT_ONLY

CURLOPT_USE_SSL

Use TLS/SSL. See CURLOPT_USE_SSL

CURLOPT_RESOLVE

Provide fixed/fake name resolves. See CURLOPT_RESOLVE

CURLOPT_DNS_INTERFACE

Bind name resolves to this interface. See CURLOPT_DNS_INTERFACE

CURLOPT_DNS_LOCAL_IP4

Bind name resolves to this IP4 address. See CURLOPT_DNS_LOCAL_IP4

CURLOPT_DNS_LOCAL_IP6

Bind name resolves to this IP6 address. See CURLOPT_DNS_LOCAL_IP6

CURLOPT_DNS_SERVERS

Preferred DNS servers. See CURLOPT_DNS_SERVERS

CURLOPT_ACCEPTTIMEOUT_MS

Timeout for waiting for the server's connect back to be accepted. SeeCURLOPT_ACCEPTTIMEOUT_MS

SSL and SECURITY OPTIONS

CURLOPT_SSLCERT

Client cert. See CURLOPT_SSLCERT

CURLOPT_SSLCERTTYPE

Client cert type. See CURLOPT_SSLCERTTYPE

CURLOPT_SSLKEY

Client key. See CURLOPT_SSLKEY

CURLOPT_SSLKEYTYPE

Client key type. See CURLOPT_SSLKEYTYPE

CURLOPT_KEYPASSWD

Client key password. See CURLOPT_KEYPASSWD

CURLOPT_SSL_ENABLE_ALPN

Enable use of ALPN. See CURLOPT_SSL_ENABLE_ALPN

CURLOPT_SSL_ENABLE_NPN

Enable use of NPN. See CURLOPT_SSL_ENABLE_NPN

CURLOPT_SSLENGINE

Use identifier with SSL engine. See CURLOPT_SSLENGINE

CURLOPT_SSLENGINE_DEFAULT

Default SSL engine. See CURLOPT_SSLENGINE_DEFAULT

CURLOPT_SSL_FALSESTART

Enable TLS False Start. See CURLOPT_SSL_FALSESTART

CURLOPT_SSLVERSION

SSL version to use. See CURLOPT_SSLVERSION

CURLOPT_SSL_VERIFYHOST

Verify the host name in the SSL certificate. See CURLOPT_SSL_VERIFYHOST

CURLOPT_SSL_VERIFYPEER

Verify the SSL certificate. See CURLOPT_SSL_VERIFYPEER

CURLOPT_SSL_VERIFYSTATUS

Verify the SSL certificate's status. See CURLOPT_SSL_VERIFYSTATUS

CURLOPT_CAINFO

CA cert bundle. See CURLOPT_CAINFO

CURLOPT_ISSUERCERT

Issuer certificate. See CURLOPT_ISSUERCERT

CURLOPT_CAPATH

Path to CA cert bundle. See CURLOPT_CAPATH

CURLOPT_CRLFILE

Certificate Revocation List. See CURLOPT_CRLFILE

CURLOPT_CERTINFO

Extract certificate info. See CURLOPT_CERTINFO

CURLOPT_PINNEDPUBLICKEY

Set pinned SSL public key . See CURLOPT_PINNEDPUBLICKEY

CURLOPT_RANDOM_FILE

Provide source for entropy random data. See CURLOPT_RANDOM_FILE

CURLOPT_EGDSOCKET

Identify EGD socket for entropy. See CURLOPT_EGDSOCKET

CURLOPT_SSL_CIPHER_LIST

Ciphers to use. See CURLOPT_SSL_CIPHER_LIST

CURLOPT_SSL_SESSIONID_CACHE

Disable SSL session-id cache. See CURLOPT_SSL_SESSIONID_CACHE

CURLOPT_SSL_OPTIONS

Control SSL behavior. See CURLOPT_SSL_OPTIONS

CURLOPT_KRBLEVEL

Kerberos security level. See CURLOPT_KRBLEVEL

CURLOPT_GSSAPI_DELEGATION

Disable GSS-API delegation. See CURLOPT_GSSAPI_DELEGATION

SSH OPTIONS

CURLOPT_SSH_AUTH_TYPES

SSH authentication types. See CURLOPT_SSH_AUTH_TYPES

CURLOPT_SSH_HOST_PUBLIC_KEY_MD5

MD5 of host's public key. See CURLOPT_SSH_HOST_PUBLIC_KEY_MD5

CURLOPT_SSH_PUBLIC_KEYFILE

File name of public key. See CURLOPT_SSH_PUBLIC_KEYFILE

CURLOPT_SSH_PRIVATE_KEYFILE

File name of private key. See CURLOPT_SSH_PRIVATE_KEYFILE

CURLOPT_SSH_KNOWNHOSTS

File name with known hosts. See CURLOPT_SSH_KNOWNHOSTS

CURLOPT_SSH_KEYFUNCTION

Callback for known hosts handling. See CURLOPT_SSH_KEYFUNCTION

CURLOPT_SSH_KEYDATA

Custom pointer to pass to ssh key callback. See CURLOPT_SSH_KEYDATA

OTHER OPTIONS

CURLOPT_PRIVATE

Private pointer to store. See CURLOPT_PRIVATE

CURLOPT_SHARE

Share object to use. See CURLOPT_SHARE

CURLOPT_NEW_FILE_PERMS

Mode for creating new remote files. See CURLOPT_NEW_FILE_PERMS

CURLOPT_NEW_DIRECTORY_PERMS

Mode for creating new remote directories. See CURLOPT_NEW_DIRECTORY_PERMS

TELNET OPTIONS

CURLOPT_TELNETOPTIONS

TELNET options. See CURLOPT_TELNETOPTIONS

RETURN VALUE

CURLE_OK (zero) means that the option was set properly, non-zero means an error occurred as<curl/curl.h> defines. See the libcurl-errors man page for the full list with descriptions.

If you try to set an option that libcurl doesn't know about, perhaps because the library is too old to support it or the option was removed in a recent version, this function will return CURLE_UNKNOWN_OPTION. If support for the option was disabled at compile-time, it will return CURLE_NOT_BUILT_IN.

EXAMPLE

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  res = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}

SEE ALSO

curl_easy_initcurl_easy_cleanupcurl_easy_resetcurl_easy_getinfocurl_multi_setopt


http://curl.haxx.se/libcurl/c/curl_easy_setopt.html


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以通过使用curl_easy_setopt函数设置输出处理函数,具体的语法为:curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data); 其中 write_data 是输出处理函数的名称。 ### 回答2: 在使用cURL库中的curl_easy_setopt函数时,可以通过设置输出处理函数来处理cURL执行操作的输出。设置输出处理函数的步骤如下: 1. 创建一个用于处理输出的函数。 这个函数的格式必须符合以下原型: size_t handle_output(void *ptr, size_t size, size_t nmemb, void *userdata); 函数的参数依次为ptr,size,nmemb和userdata。其中,ptr是接收到的数据指针,size是每个数据项的大小,nmemb是接收到的数据项数目,userdata是一个用户指定的指针,可用于传递自定义数据。 2. 在代码中定义代表cURL会话的CURL类型的变量,并通过curl_easy_init函数进行初始化。 3. 调用curl_easy_setopt函数,并将设置项设为CURLOPT_WRITEFUNCTION,第二个参数为输出处理函数的指针。 4. 如果需要传递自定义数据给输出处理函数,则还可以使用curl_easy_setopt函数设置CURLOPT_WRITEDATA选项,第二个参数为自定义数据的指针。 5. 执行需要的cURL操作,如发送HTTP请求。 下面是一个简单的示例代码,演示如何设置输出处理函数: ```c #include <stdio.h> #include <curl/curl.h> size_t handle_output(void *ptr, size_t size, size_t nmemb, void *userdata) { // 处理接收到的数据 // ptr是接收到的数据指针,size是每个数据项的大小,nmemb是接收到的数据项数目,userdata是自定义数据指针 // 示例代码中,直接打印接收到的数据到控制台 size_t total_size = size * nmemb; fwrite(ptr, 1, total_size, stdout); return total_size; } int main() { CURL *curl; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com"); // 设置请求的URL curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handle_output); // 设置输出处理函数 // 可选:设置自定义数据指针 // curl_easy_setopt(curl, CURLOPT_WRITEDATA, custom_data_ptr); CURLcode res = curl_easy_perform(curl); // 执行请求操作 if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_easy_cleanup(curl); } return 0; } ``` 以上是设置curl_easy_setopt的输出处理函数的简要步骤和示例代码。根据需要,可以在输出处理函数中自定义处理接收到的数据。 ### 回答3: curl_easy_setopt函数libcurl库中用于设置选项函数,可以通过该函数设置curl的各种行为和选项。其中一个常见的选项设置输出处理函数,即设置curl用于处理响应数据的回调函数。 要设置curl的输出处理函数,需要使用curl_easy_setopt函数,并将选项参数设置CURLOPT_WRITEFUNCTION,然后将回调函数作为参数传递给该选项。 具体的代码如下所示: ``` // 声明输出处理函数,需要符合curl_write_callback类型的定义 size_t writeCallback(char* ptr, size_t size, size_t nmemb, void* userdata) { // 在这里对收到的数据进行处理 // ptr:收到的数据指针 // size:每个数据元素的大小 // nmemb:数据元素的数量 // userdata:用户自定义数据指针 // 返回值表示实际处理的字节数 } // 初始化curl CURL* curl = curl_easy_init(); if(curl) { // 设置输出处理函数 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); // 这里可以继续设置其他选项... // 执行curl请求 CURLcode res = curl_easy_perform(curl); if(res != CURLE_OK) { // 请求失败的处理逻辑... } // 清理curl curl_easy_cleanup(curl); } ``` 在上述代码中,通过curl_easy_setopt函数选项参数设置CURLOPT_WRITEFUNCTION,并将回调函数writeCallback作为参数传递。在writeCallback回调函数中,可以对收到的响应数据进行处理。在函数内部,可以通过参数ptr、size和nmemb访问到接收到的数据。需要注意,writeCallback回调函数的返回值需要表示实际处理的字节数。 通过这种方式,我们可以自定义输出处理函数来处理curl接收到的响应数据,实现自己的数据处理逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值