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(char *buffer, size_t size, size_t nmemb, std::string *userp) |
---|
6 | { |
---|
7 | std::cerr << "write_data called\n"; |
---|
8 | std::string s; |
---|
9 | size_t l = size*nmemb; |
---|
10 | s.resize(l+1); |
---|
11 | for (unsigned int i=0; i<l; i++) |
---|
12 | s[i] = ((char*)buffer)[i]; |
---|
13 | s[l] = '\0'; |
---|
14 | std::cerr << s << std::endl; |
---|
15 | for (size_t i=0; i<l; i++) |
---|
16 | { |
---|
17 | (*userp).push_back(buffer[i]); |
---|
18 | } |
---|
19 | |
---|
20 | return l; |
---|
21 | } |
---|
22 | int main() |
---|
23 | { |
---|
24 | curl_global_init(CURL_GLOBAL_ALL); |
---|
25 | CURL *c = curl_easy_init(); |
---|
26 | curl_easy_setopt(c,CURLOPT_URL,"http://localhost:5050/cgi-bin/prenv/aap/noot"); |
---|
27 | std::string header; |
---|
28 | std::string body; |
---|
29 | std::string *h = &header; |
---|
30 | std::string *b = &body; |
---|
31 | curl_easy_setopt(c, CURLOPT_NOPROGRESS, 1L); |
---|
32 | curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, write_data); |
---|
33 | curl_easy_setopt(c, CURLOPT_WRITEHEADER, &header); |
---|
34 | curl_easy_setopt(c, CURLOPT_WRITEDATA, &body); |
---|
35 | |
---|
36 | int rc = curl_easy_perform(c); |
---|
37 | std::cout << "rc from perform: " << rc << std::endl; |
---|
38 | std::cout << header; |
---|
39 | std::cout << body; |
---|
40 | |
---|
41 | /* cleanup curl stuff */ |
---|
42 | curl_easy_cleanup(c); |
---|
43 | |
---|
44 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.