zoukankan      html  css  js  c++  java
  • 使用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;

    }

  • 相关阅读:
    实习第五十七天
    武汉第五十六天
    武汉第五十五天
    常用环境配置
    http 基本验证(nginx)
    nginx configuration
    docker run demo
    初识Hadoop
    大数据简介
    HDFS 存放策略
  • 原文地址:https://www.cnblogs.com/LinuxHunter/p/2012563.html
Copyright © 2011-2022 走看看