• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LinuxHunter
原创+技巧=无坚不摧
博客园    首页    新随笔    联系   管理    订阅  订阅
使用CURL库下载文件
使用CURL库下载文件

#include <curl/curl.h>
#pragma comment( lib, "libcurl.lib" )


size_t write_data(char *buffer,size_t size, size_t nitems,void *outstream)

{

  int written = fwrite(buffer, size, nitems, (FILE*)outstream);

  return written;

}


int main(int argc, char* argv[])

{

  CURL* pCurl = curl_easy_init();

  FILE* pFile = fopen( "E:/test.txt", "wb" );

  curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, (void*)pFile );

  //设置回调函数

  curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, write_data);

  curl_easy_setopt(pCurl, CURLOPT_URL, "www.google.com.hk");

  curl_easy_perform(pCurl);

  fclose(pFile);

  curl_easy_cleanup( pCurl );

  return 0;

}

posted on 2011-04-11 15:28  LinuxHunter  阅读(5851)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3