libcurl help;

This is the first time of me trying to use the libcurl library and I'm having some issues.

I think I'm not understanding points / references to well or something.

The string "WebData" isn't getting the entire page. What am I doing wrong?



Thank You!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <curl/curl.h>
#include <string>



std::string WebData = "";

size_t curl_write(std::string *wd, size_t size, size_t nmemb, void *stream)
{
    memcpy(&WebData, wd, nmemb);
    return 0;
}



int main() {
    
    CURL *curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    
    std::cout << WebData;
    
    
}
alright! I got it to work!
Now not sure if it is the right way going about it. but its working.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <curl/curl.h>
#include <string>




std::string WebData;;

size_t curl_write(void *wd, size_t size, size_t nmemb, void *stream)
{
    size_t acuallSize = size*nmemb;
    
    WebData.append((char*)wd, acuallSize);
    
    return 0;
}



int main() {
    
    CURL *curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    
    std::cout << WebData;
    
    
}
Topic archived. No new replies allowed.