在C ++中使用curl时写入回调未执行

时间:2014-08-25 22:45:22

标签: c++ curl

我试图基本上按照http://curl.haxx.se/中的示例代码来下载网页,但我的WRITEFUNCTION回调根本没有被执行。函数write_callback中的printf消息不会显示(但它确实显示“Ok I guess it working(?)”消息。

自从我在C工作以来已经有一段时间了,所以我可能会生锈......

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

size_t write_callback (void *ptr, size_t size, size_t nmemb, void *userdata);


int main()
{
    printf ("Hello CURL 1.0\n");

    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();

    if (curl)
    {
        curl_easy_setopt (curl, CURLOPT_URL, "http://artifactory.ds.adp.com/artifactory/webapp/home.html");
        curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback);

        res = curl_easy_perform(curl);

        if (res != CURLE_OK)
        {
            printf ("Failed", curl_easy_strerror(res));
        }
        else
        {
            printf ("Ok I guess it worked?\n");
        }
    }

    /* always cleanup */ 
    curl_easy_cleanup(curl);

    return 0;
}

size_t write_callback (void *ptr, size_t size, size_t nmemb, void *userdata)
{
    printf ("This is my callback function.\n");
    return 0;
}

1 个答案:

答案 0 :(得分:0)

代理服务器阻止了连接。