Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4732449
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2010-05-03 22:33:12

CALLBACK OPTIONS

CURLOPT_WRITEFUNCTION

函数指针: size_t function( void *ptr, size_t size, size_t nmemb, void *stream);

作用: libcurl接收到要保存的数据时调用此函数, ptr所指数据大小为 size*nmemb. 返回实际处理的数据大小,如果返回值不等于传递给函数的数据大小,则报错,并返回CURLE_WIRTE_ERROR

: 如果此参数置为NULL, 则会调用默认的函数,将数据写入到FILE*(CURLOPT_WRITEDATA 给出)


此回调函数会尽量处理更多数据,但是传递给回调函数的数据最大值定义在curl.h文件中.

CURL_MAX_WRITE_SIZE = 16k


CURLOPT_WRITEDATA

数据指针:传递给写函数,

作用:如果使用了 CURLOPT_WRITEFUNCTION 参数, 可以使用这个指针作为输入,如果没有使用CURLOPT_WRITEFUNCTION, 则必需给出一个FILE*类型, libcurl会将其传递给fwrite()



CURLOPT_READFUNCTION

函数指针: size_t function( void *ptr, size_t size, size_t nmemb, void *stream);

作用:libcurl需要读取数据并发送出去时调用此函数, ptr所指数据大小返回实际处理的数据大小,如果返回值为0,标志结束传输

:如果此参数为NULL, 或者不设置, 将调用默认的函数,fread()FILE* (CURLOPT_READDATA 设置)


CURLOPT_READDATA

...


CURLOPT_IOCTLFUNCTION

处理特殊I/O事件: 仅用在 rewinding the read data stream 回环数据(用于处理HTTP put post 多次传输认证 multi-psss authentication 方法)


CURLOPT_IOCTLDATA

...


CURLOPT_SOCKOPTFUNCTION

libcurl调用: socket(), connect()

设置 CURLSOCKTYPE_IPCXN (meaning the control connection in the FTP case)


CURLOPT_SOCKOPTDATA

...


CURLOPT_PROGRESSFUNCTION CURLOPT_PROGRESSDATA

CURLOPT_HEADERFUNCTION

函数指针: size_t function( void *ptr, size_t size, size_t nmemb, void *stream);

作用 :libcurl收到header 数据, 会调用此函数处理. 当全部headerlines传递给回调函数后,此函数调用一次(为每个header), 可以使用此函数解析header

命名为stream的参数是你调用CURLOPT_WRITEHEADER设置的

函数应当返回所处理的实际数据大小, 或者返回-1 报错


Since 7.14.1: When a server sends a chunked encoded transfer, it may contain a trailer. That trailer is identical to a HTTP header and if such a trailer is received it is passed to the application using this callback as well. There are several ways to detect it being a trailer and not an ordinary header: 1) it comes after the response-body. 2) it comes after the final header line (CR LF) 3) a Trailer: header among the response-headers mention what header to expect in the trailer.


CURLOPT_WRITEHEADER

接收到的数据中的header部分写入到此 指针



CURLOPT_DEBUGFUNCTION

int curl_debug_callback (CURL *, curl_infotype, char *, size_t, void *)

用以调试


CURLOPT_DEBUGDATA



CURLOPT_SSL_CTX_FUNCTION

CURLcode sslctxfun(CURL *curl, void *sslctx, void *parm)

libcurl调用此函数在初始化一个SSL连接之前设置了全部的SSL连接参数之后, 是应用程序修改SSL连接设置的最后机会


CURLOPT_SSL_CTX_DATA


CURLOPT_CONV_TO_NETWORK_FUNCTION

CURLOPT_CONV_FROM_NETWORK_FUNCTION

CURLOPT_CONV_FROM_UTF8_FUNCTION





NETWORK OPTIONS

CURLOPT_URL

CURLOPT_INTERFACE

Pass a char * as parameter. This set the interface name to use as outgoing network interface. The name can be an interface name, an IP address or a host name.



CURLOPT_BUFFERSIZE

Pass a long specifying your preferred size (in bytes) for the receive buffer in libcurl. The main point of this would be that the write callback gets called 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. (Added in 7.10)

This size is by default set as big as possible (CURL_MAX_WRITE_SIZE), so it only makes sense to use this option if you want it smaller.



CURLOPT_PORT

Pass a long specifying what remote port number to connect to, instead of the one specified in the URL or the default port for the used protocol.



NAMES and PASSWORDS OPTIONS (Authentication)





HTTP OPTIONS

CURLOPT_ENCODING

Three encodings are supported: identity gzip a zero-length string

This is a request, not an order





CURLOPT_PUT

A non-zero parameter tells the library to use HTTP PUT to transfer data. The data should be set with CURLOPT_READDATA and CURLOPT_INFILESIZE.

This option is deprecated and starting with version 7.12.1 you should instead use CURLOPT_UPLOAD.





CURLOPT_POST

非零:告知libcurl执行一个常规的HTTP POST, libcurl会使用"Content-Type: application/x-www-form-urlencoded"header

CURLOPT_POSTFIELDS 描述所传输的数据

CURLOPT_POSTFIELDSIZE描述数据的大小



可以提供数据来 POST

使用: CURLOPT_READFUNCTION and CURLOPT_READDATA 参数 (请确保不要设置 CURLOPT_POSTFIELDS, 或者置其为NULL)

When providing data with a callback, you must transmit it using chunked transfer-encoding or you must set the size of the data with the CURLOPT_POSTFIELDSIZE option.


可以重写默认的POST 内容类型使用 CURLOPT_HTTPHEADER.


当设置 CURLOPT_POST 非零时, 会自动CURLOPT_NOBODY to 0


如果声明了一个POST 请求后, 想要使用同一个handle GET 或者 HEAD, 必需设置新的请求类型使用 CURLOPT_NOBODY or CURLOPT_HTTPGET or similar.




CURLOPT_POSTFIELDS

必需确保数据格式服务器可以 解析, libcurl不会转化或者encode. 但是大部分夫服务器假定这些数据是 url-encoded .


当此选项使用后 POST 是一个 application/x-www-form-urlencoded 类型


如果想要发送一个 zero-byte POST 需要设置CURLOPT_POSTFIELDSIZE 0

CURLOPT_POSTFIELDS to NULL or "" 仅仅设置不发送指定数据, libcurl会认为使用回调函数发送数据


CURLOPT_HTTPHEADER

Pass a pointer to a linked list of HTTP headers to pass to the server in your HTTP request. The linked list should be a fully valid list of struct curl_slist structs properly filled in. Use curl_slist_append(3) to create the list and curl_slist_free_all(3) to clean up an entire list. If you add a header that is otherwise generated and used by libcurl internally, your added one will be used instead. If you add a header with no contents as in 'Accept:' (no data on the right side of the colon), the internally used header will get disabled. Thus, using this option you can add new headers, replace internal headers and remove internal headers. To add a header with no contents, make the contents be two quotes: "". The headers included in the linked list must not be CRLF-terminated, because curl adds CRLF after each header item. Failure to comply with this will result in strange bugs because the server will most likely ignore part of the headers you specified.

The first line in a request (containing the method, usually a GET or POST) is not a header and cannot be replaced using this option. Only the lines following the request-line are headers. Adding this method line in this list of 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 CURLOPT_COOKIE, CURLOPT_USERAGENT and CURLOPT_REFERER.



CURLOPT_HTTP_VERSION

force libcurl 使用 特定的 HTTP_VERSION

CURL_HTTP_VERSION_NONE

We don't care about what version the library uses. libcurl will use whatever it thinks fit.

CURL_HTTP_VERSION_1_0

Enforce HTTP 1.0 requests.

CURL_HTTP_VERSION_1_1

Enforce HTTP 1.1 requests.



CURLOPT_HTTP_CONTENT_DECODING

Pass a long to tell libcurl how to act on content decoding. If set to zero, content decoding will be disabled. If set to 1 it is enabled. Note however that libcurl has no default content decoding but requires you to use CURLOPT_ENCODING for that. (added in 7.16.2)

CURLOPT_HTTP_TRANSFER_DECODING

Pass a long to tell libcurl how to act on transfer decoding. If set to zero, transfer decoding will be disabled, if set to 1 it is enabled (default). libcurl does chunked transfer decoding by default unless this option is set to zero. (added in 7.16.2)



CONNECTION OPTIONS

CURLOPT_TIMEOUT




Example:

#include
#include

int main(void)
{

    URL *curl;
    CURLcode res;
    struct curl_slist *slist  =  NULL;

    slist  =  curl_slist_append(slist, "");

   
    curl  =  curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, "");  // arg(url)
        curl_easy_setopt(curl, CURLOPT_INTERFACE, "192.168.16.60");   // interface name or hostname or IP address
       
        curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // arg(http_version)
       
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "User-Agent: PEAR HTTP_Request class\r\n");
       
        curl_easy_setopt(curl, CURLOPT_ENCODING, gzip);            // Accept-Encoding
        curl_easy_setopt(curl, CURLOPT_POSTFILEDSIZE, post_data.length());     // Content-Length:
           
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); // HEADER
       
        curl_esay_setopt(curl, CURLOPT_POST, TRUE); // POST

        curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
        curl_easy_setopt(curl, CURLOPT_READDATA, read_buff);        // or FILE*
       
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTIOIN, write_callback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, write_buff);        // or FILE*
       
       
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);            // Used to debug
        curl_easy_setopt(curl, CURLOPT_STDERR, pFILE_error_info); // save error info in the file or stderr
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buff); // error_buff used to save error info
        res = curl_easy_perform(curl);

       
       
        curl_easy_cleanup(curl);
    }
    curl_slist_freeall(slist);
    return 0;
   
}

size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
   
}

size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
    // .....  
}
阅读(3209) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-05-31 22:35:11

MBT is based on Africa's indigenous people to create innovative walking barefoot, and wear this shoe can stimulate the body to relax the muscles so that the muscles of heat to be released, consumed calories, thus to achieve weight loss results. MBT's pursuit of beauty in order to satisfy customers, design a variety of styles, such as Mbt Chapa shoe, MBT Lami Shoe