• 从curl命令获取libcurl的用法


    libcurl的用法参数太多 有时候弄不好 可以先用curl命令实现了 然后获取相应的libcurl代码

    比如要上传文件

    curl -T d:/h.txt http://demo.xudp.cn/up/

    下面获取相应的代码

    curl --libcurl d:/curl.txt -T d:/h.txt http://demo.xudp.cn/up/

    相应的代码就放到d:/curl.txt里面了

    /********* Sample code generated by the curl command line tool **********
     * All curl_easy_setopt() options are documented at:
     * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
     ************************************************************************/
    #include <curl/curl.h>
    
    int main(int argc, char *argv[])
    {
      CURLcode ret;
      CURL *hnd;
    
      hnd = curl_easy_init();
      curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
      curl_easy_setopt(hnd, CURLOPT_INFILESIZE_LARGE, (curl_off_t)5195);
      curl_easy_setopt(hnd, CURLOPT_URL, "http://demo.xudp.cn/up/h.txt");
      curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
      curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L);
      curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.65.3");
      curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
      curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
      curl_easy_setopt(hnd, CURLOPT_HTTP09_ALLOWED, 1L);
      curl_easy_setopt(hnd, CURLOPT_CAINFO, "C:\Windows\system32\curl-ca-bundle.crt");
      curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, "C:\Users\Administrator\AppData\Roaming/_ssh/known_hosts");
      curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
    
      /* Here is a list of options the curl code used that cannot get generated
         as source easily. You may select to either not use them or implement
         them yourself.
    
      CURLOPT_WRITEDATA set to a objectpointer
      CURLOPT_INTERLEAVEDATA set to a objectpointer
      CURLOPT_WRITEFUNCTION set to a functionpointer
      CURLOPT_READDATA set to a objectpointer
      CURLOPT_READFUNCTION set to a functionpointer
      CURLOPT_SEEKDATA set to a objectpointer
      CURLOPT_SEEKFUNCTION set to a functionpointer
      CURLOPT_ERRORBUFFER set to a objectpointer
      CURLOPT_STDERR set to a objectpointer
      CURLOPT_HEADERFUNCTION set to a functionpointer
      CURLOPT_HEADERDATA set to a objectpointer
    
      */
    
      ret = curl_easy_perform(hnd);
    
      curl_easy_cleanup(hnd);
      hnd = NULL;
    
      return (int)ret;
    }
    /**** End of sample code ****/
  • 相关阅读:
    3.无重复字符的最长字串
    k-近邻算法(KNN)
    决策树
    解决anaconda与pycharm冲突导致import无法使用
    2.两数相加
    1.两数之和
    数学建模第七章 数理统计
    数学建模第六章 微分方程建模
    Web(4)servlet
    阿里云卸载自带的JDK,安装JDK完成相关配置
  • 原文地址:https://www.cnblogs.com/yuandaozhe/p/12091732.html
Copyright © 2020-2023  润新知