编译时,出现缺少 curl 问题的解决

来源:互联网 发布:centos 无法打开https 编辑:程序博客网 时间:2024/06/06 20:36

/** Description *  Sample project in C using libcurl. *  Requests the rate data for EUR/USD, USD/CAD, AND USD/JPY and outputs them to standard output. */#include <stdio.h>#include <curl/curl.h>int main() {    CURL *curl;    CURLcode res;        curl = curl_easy_init();    if(curl) {        curl_easy_setopt(curl, CURLOPT_URL,                         "http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD%2CUSD_CAD%2CUSD_JPY");        struct curl_slist *chunk = NULL;        // uncomment to add authorization header: not required for sandbox        // chunk = curl_slist_append(chunk, "Authorization: Bearer <your access token>");                /* use custom headers */        res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);                /* Perform the request, res will get the return code */        res = curl_easy_perform(curl);                /* Check for errors */        if(res != CURLE_OK) {            fprintf(stderr, "curl_easy_perform() failed: %s\n",                    curl_easy_strerror(res));        }                /* always cleanup */        curl_easy_cleanup(curl);        /* free the custom headers */         curl_slist_free_all(chunk);    }    return 0;}


安装

apt-get install libcurl4-gnutls-dev

编译

gcc APISample.c -lcurl -o rate_fetcher

运行

./rate_fetcher

原创粉丝点击