curl_easy_setopt
通过设置适当的选项,来更改curl的行为、
危险
错误的输入值可能会导致curl行为异常
详细参考curl_easy_setopt
说明
设置write function(CURLoption.CURLOPT_WRITEFUNCTION
)
传入write function
回调,替代默认的write 函数
执行传输(curl_easy_perform)时,一旦收到需要保存的数据,libcurl 就会调用此回调函数,对于大多数传输,此回调会被多次调用
声明
int curl_easy_setopt(int option, mixed param)
参数
参数名 | 描述 |
---|---|
option | CURLoption 选项,constant.gs文件中列出了一些常用选项 |
param | 目前该参数支持int、float、string类型 |
返回值
使用方式
void write_function(string data)
{
printf("data: %s\n", data);
}
object s = curl.curl_create_session();
string url = "http://tools.jszx.g-bits.com:3000/";
s.curl_easy_setopt(CURLoption.CURLOPT_URL, url);
// 设置write function后,write_fn即会替换掉libcurl默认的打印行为
s.curl_easy_setopt(CURLoption.CURLOPT_WRITEFUNCTION, (: write_function :));
int res = s.curl_easy_perform();
// do something
s.curl_easy_cleanup();
s.close();