简体   繁体   English

使用cURL将网页保存到C ++中的内存中

[英]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. 由于我是通过手机编写的,因此无法插入代码段。

或使用Urdl

You can use a C++ object to manage the state of the curl request and receive data 您可以使用C ++对象管理curl请求的状态并接收数据

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);
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM