Diety Dieticheskie-produkty Protsedury Sredstva Uprajneniya Fitnes Gimnastika Yoga Pitanie Tsellyulit Zdorove Krasota

cURL is a great command-line tool for making network requests. It specially becomes handy while making HTTP requests from command line for troubleshooting / monitoring purposes. libcurl is considered to be high-level tool that have bindings for many high-level languages which make it easy for developers to use cURL features from programming language of their choice.

cURL uses libcurl behind the scene but since cURL is a command-line tool we cannot get idea of what code gets executed when we issue a cURL request. But if you want to get equivalent C Code for a cURL request it is quite easy to get it, you just have to pass –libcurl option with the cURL request and you are done. Let me show you how to do this.


# A simple cURL Request
$ curl --libcurl name_of_file.c

Following is the C Code that gets generated if you issue the above mentioned command.

/********* Sample code generated by the curl command line tool **********
 * All curl_easy_setopt() options are documented at:

int main(int argc, char *argv[])
  CURLcode ret;
  CURL *hnd = curl_easy_init();
  curl_easy_setopt(hnd, CURLOPT_URL, "");
  curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1);
  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5");
  curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, your_ssh_key_path);
  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50);
  ret = curl_easy_perform(hnd);

  /* 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_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_SOCKOPTFUNCTION set to a functionpointer
  CURLOPT_SOCKOPTDATA set to a objectpointer

  return (int)ret;
/**** End of sample code ****/

I hope you like this quick tip.

Tagged with:

2 Responses to How to get C Code of a cURL Request

  1. I’m not positive the place you’re getting your information, but great topic. I needs to spend a while finding out much more or understanding more. Thanks for magnificent information I was in search of this information for my mission.

  2. ilatif.bwp says:

    Thanks for liking the effort. We are really excited to bring awesome stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *