V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
Livid
V2EX  ›  HTTP

curl --libcurl

  •  
  •   Livid · 2019-03-22 07:27:29 +08:00 · 4319 次点击
    这是一个创建于 2072 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如果在使用 curl 命令行的时候加上 --libcurl 参数,就可以生成用 libcurl 完成本次请求的 C 语言源代码文件。比如:

    curl --libcurl example.c https://www.example.org/
    

    然后获得的 example.c 是这样的:

    /********* 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_URL, "https://www.example.org/");
      curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
      curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.60.0");
      curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
      curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
      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 ****/
    
    2 条回复    2019-03-29 08:29:29 +08:00
    ech0x
        1
    ech0x  
       2019-03-22 08:38:28 +08:00 via iPhone
    这个可以编译在路由器固件上诶。
    CSM
        2
    CSM  
       2019-03-29 08:29:29 +08:00
    要是再结合 Chrome 的 copy as cURL 就更好玩了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5881 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:06 · PVG 10:06 · LAX 18:06 · JFK 21:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.