官方的例子:
https://curl.haxx.se/libcurl/c/example.html
事实上我们集成使用时希望
1.非阻塞,方便随时取消
2.看到进度
3.逐个下载
其他的暂时没啥叼用。
融合官网例子,自己做的测试代码如下,改改封装可用了:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#ifdef _WIN32
#define WAITMS(x) Sleep(x)
#else
/* Portable sleep for platforms other than Windows. */
#define WAITMS(x) \
struct timeval wait = { 0, (x) * 1000 }; \
(void)select(0, NULL, NULL, NULL, &wait);
#endif
#define HTTPURL "http://abc.efg.com/ddd.php"
struct MemoryStruct {
char *memory;
size_t size;
size_t length;
};
static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
printf("WriteMemoryCallback\n");
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)use