Read the Web page data into memory through Libcurl for further processing.
Key code:
BOOL readtocontentbuff (const char* URL, string& content) {curl* conn = NULL;
Curlcode code = Curle_failed_init;
Char Errorbuffer[curl_error_size];
conn = Curl_easy_init ();
if (conn = = NULL) {goto exit_code_readtocontentbuff;
}//code = CURL_EASY_SETOPT (conn, Curlopt_url, URL);
If (code!= CURLE_OK) {goto exit_code_readtocontentbuff;
}//code = CURL_EASY_SETOPT (conn, Curlopt_errorbuffer, Errorbuffer);
If (code!= CURLE_OK) {goto exit_code_readtocontentbuff;
}//code = CURL_EASY_SETOPT (conn, curlopt_followlocation, 1);
If (code!= CURLE_OK) {goto exit_code_readtocontentbuff;
}//code = CURL_EASY_SETOPT (conn, curlopt_writefunction, writer);
If (code!= CURLE_OK) {goto exit_code_readtocontentbuff;
}//code = CURL_EASY_SETOPT (conn, curlopt_writedata, &content);
If (code!= CURLE_OK) {goto exit_code_readtocontentbuff;
}//code = CURL_EASY_PERFORM (conn);
If (code!= CURLE_OK) { Goto Exit_code_readtocontentbuff;
}//EXIT_CODE_READTOCONTENTBUFF:IF (conn) {CURL_EASY_CLEANUP (conn);
return (Code = = CURLE_OK); }
The specific code for the Witer function is as follows:
int writer (char *data, size_t size, size_t nmemb, String *writerdata) {
unsigned long sizes = size * NMEMB;
if (Writerdata = = NULL) {return
0;
}
Writerdata->append (data, sizes);
return sizes;
}
Mylaf
2017-08-10 2010