Line | |
---|
1 | // http://curl.haxx.se/libcurl/c/libcurl-tutorial.html |
---|
2 | #include <iostream> |
---|
3 | #include <curl/curl.h> |
---|
4 | |
---|
5 | size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) |
---|
6 | { |
---|
7 | int written = fwrite(buffer, size, nmemb, (FILE *)userp); |
---|
8 | return written; |
---|
9 | } |
---|
10 | int main() |
---|
11 | { |
---|
12 | static const char *headerfilename = "head.out"; |
---|
13 | FILE *headerfile; |
---|
14 | static const char *bodyfilename = "body.out"; |
---|
15 | FILE *bodyfile; |
---|
16 | curl_global_init(CURL_GLOBAL_ALL); |
---|
17 | CURL *c = curl_easy_init(); |
---|
18 | curl_easy_setopt(c,CURLOPT_URL,"http://localhost:5050/cgi-bin/prenv/aap/noot"); |
---|
19 | curl_easy_setopt(c, CURLOPT_NOPROGRESS, 1L); |
---|
20 | curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, write_data); |
---|
21 | headerfile = fopen(headerfilename,"w"); |
---|
22 | if (headerfile == NULL) { |
---|
23 | curl_easy_cleanup(c); |
---|
24 | return -1; |
---|
25 | } |
---|
26 | bodyfile = fopen(bodyfilename,"w"); |
---|
27 | if (bodyfile == NULL) { |
---|
28 | curl_easy_cleanup(c); |
---|
29 | return -1; |
---|
30 | } |
---|
31 | curl_easy_setopt(c, CURLOPT_WRITEHEADER, headerfile); |
---|
32 | curl_easy_setopt(c, CURLOPT_WRITEDATA, bodyfile); |
---|
33 | |
---|
34 | int rc = curl_easy_perform(c); |
---|
35 | std::cout << "rc from perform: " << rc << std::endl; |
---|
36 | fclose(headerfile); |
---|
37 | fclose(bodyfile); |
---|
38 | |
---|
39 | /* cleanup curl stuff */ |
---|
40 | curl_easy_cleanup(c); |
---|
41 | |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.