int NQDownload::NQDown_src( const char* s_outfile,const char* plist_url )
{
CURL *curl;
CURLcode res;
char buffer[10];
curl = curl_easy_init();
string _list=s_outfile;
string _path_invers,_path="md ";
int _count=0;
for (int _index=_list.size();_index>0;_index--)
{
if (_list[_index-1]=='/')
{
_count++;
if (_count==1)
{
_count=_index-1;
break;
}
}
};
_path_invers=_list.substr(0,_count);
for(int _pindex=0;_pindex<_path_invers.size();_pindex++)
{
if (_path_invers[_pindex]=='/')
{
_path.push_back('\\');
}
else
_path.push_back(_path_invers[_pindex]);
};
system(_path.c_str());
if (curl)
{
//创建写入的文件。
FILE *outfile;
outfile = fopen(s_outfile,"wb");
curl_easy_setopt(curl, CURLOPT_URL, plist_url);
if(outfile)
{
//指定写入的文件指针。
curl_easy_setopt(curl, CURLOPT_FILE, outfile);
}
//设置写数据的回调函数。
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
//关闭文件
fclose(outfile);
return 1;
}
else
{
return -1;
}
}cocos2dx之curl下载
最新推荐文章于 2015-01-21 16:13:08 发布
本文介绍了一个使用C++实现的网络文件下载功能。该功能利用libcurl库进行HTTP请求,并将远程服务器上的文件下载到本地指定路径。文章详细展示了如何初始化CURL句柄、设置下载URL、创建目标文件及执行下载过程。

2566

被折叠的 条评论
为什么被折叠?



