Git init
[external/curl.git] / docs / examples / getinfo.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include <stdio.h>
11 #include <curl/curl.h>
12
13 int main(void)
14 {
15   CURL *curl;
16   CURLcode res;
17
18   /* http://curl.haxx.se/libcurl/c/curl_easy_init.html */
19   curl = curl_easy_init();
20   if(curl) {
21     /* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTURL */
22     curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/");
23     /* http://curl.haxx.se/libcurl/c/curl_easy_perform.html */
24     res = curl_easy_perform(curl);
25
26     if(CURLE_OK == res) {
27       char *ct;
28       /* ask for the content-type */
29       /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */
30       res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
31
32       if((CURLE_OK == res) && ct)
33         printf("We received Content-Type: %s\n", ct);
34     }
35
36     /* always cleanup */
37     /* http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html */
38     curl_easy_cleanup(curl);
39   }
40   return 0;
41 }