httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
Livid
279.77D
565.83D
V2EX  ›  HTTP

curl --libcurl

  •  
  •   Livid ·
    PRO
    · Mar 22, 2019 · 4942 views
    This topic created in 2621 days ago, the information mentioned may be changed or developed.

    如果在使用 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 replies    2019-03-29 08:29:29 +08:00
    ech0x
        1
    ech0x  
       Mar 22, 2019 via iPhone
    这个可以编译在路由器固件上诶。
    CSM
        2
    CSM  
       Mar 29, 2019
    要是再结合 Chrome 的 copy as cURL 就更好玩了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 19:46 · PVG 03:46 · LAX 12:46 · JFK 15:46
    ♥ Do have faith in what you're doing.