我想用libcurl存储字符串的结果 [英] I want to store a result for character string with libcurl

查看:65
本文介绍了我想用libcurl存储字符串的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用libcurl编写程序.

I write a program with libcurl.

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>

#define URL_MAX 256

int main(int argc, char *args[])
{
    CURL *curl;
    CURLcode res;
        curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, args[1]);
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    return 0;
}

$ gcc tinyCurl.c $ gcc curl-config --libs tinyCurl.c $ ./a.out http://example.com/ 我检查了Google搜索,但找不到. 我想存储char []而不是stdout.

$ gcc tinyCurl.c $ gcc curl-config --libs tinyCurl.c $ ./a.out http://example.com/ I examine search it google but I can't find . I want to store char[] not stdout.

是初学者的问题 先谢谢你

Is a question of the beginner thanking you in advance

推荐答案

签出curl_easy_setopt()函数.

您可能想使用CURLOPT_WRITEFUNCTION注册回调-每当接收到数据时都会调用该回调.在回调中,您可以随心所欲地处理数据.

You would want to register a callback using CURLOPT_WRITEFUNCTION - this callback would be called whenever data is received. From within the callback you could do whatever you want with the data.

注意-对于初学者来说,这有些棘手.您需要了解什么是函数指针.

Note - this is somewhat tricky stuff for a beginner. You need to understand what function pointers are.

(此答案基于阅读 http://curl.haxx中的API .se/libcurl/c/curl_easy_setopt.html -我从未使用过libcurl).

(this answer is based on reading the API in http://curl.haxx.se/libcurl/c/curl_easy_setopt.html - I have never used libcurl).

编辑-
这是在 -图书馆邮件列表.这个例子是丹尼尔·斯特伯格(Daniel Stenberg)

EDIT -
Here is an example found by googling for CURLOPT_WRITEFUNCTION, in the curl-library mailing list. This example is by Daniel Stenberg.

这篇关于我想用libcurl存储字符串的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆