prasanth madhavan
prasanth madhavan

Reputation: 11

Save a webpage to memory in C++ using cURL

I have been successful in saving a webpage to memory using a structure. But is it possible do it using a class? I am having trouble accessing the write data function inside the class.

Since I am writing from my mobile, I am unable to insert code snippets.

Upvotes: 1

Views: 561

Answers (2)

Alex Jasmin
Alex Jasmin

Reputation: 39496

You can use a C++ object to manage the state of the curl request and receive data

class CurlRequest {
public:
    CurlRequest() {
        //...
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
    }
    size_t write(void *ptr, size_t size, size_t nmemb) {
        //...
    }
private:
    CURL *curl;
    static size_t writefunc(void *ptr, size_t size, size_t nmemb, void *data) {
        CurlRequest* req = static_cast<CurlRequest*>(data);
        return req->write(ptr, size, nmemb);
    }
};

Upvotes: 2

usta
usta

Reputation: 6869

Or use Urdl.

Upvotes: 3

Related Questions