Article 3: libcurl basic programming Overview

Source: Internet
Author: User
Reprinted please indicate the source http://blog.csdn.net/yankai0219/article/details/8159697

0. Order
1. Simple Use Cases
2. Description
3. More complex examples
4. Summary

0. Order

Some time ago, the libcurl content was incorrectly supplemented as required by the project, so it was recorded. For installation instructions, refer to the official documentation. Http://curl.haxx.se/docs/install.html any time to learn anything, official documentation is definitely the best tutorial. Http://curl.haxx.se/libcurl/c/ 1. Simple casesThe following is an official basic example. Several easy interfaces are used in this example. I call it Basic Use Cases
#include <stdio.h>#include <curl/curl.h> int main(void){  CURL *curl;  CURLcode res;   curl = curl_easy_init();  if(curl) {    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");     /* Perform the request, res will get the return code */     res = curl_easy_perform(curl);    /* Check for errors */     if(res != CURLE_OK)      fprintf(stderr, "curl_easy_perform() failed: %s\n",              curl_easy_strerror(res));     /* always cleanup */     curl_easy_cleanup(curl);  }  return 0;}
2. Description:As in the translation using
As mentioned in libcurl C interface (important), the steps for easy interface are initialization, setting options, and execution. 1) initialization: curl_easy_init function: This function installs the program environment required by libcurl. It can be considered as a library loader. That is, use this function to load the library file. 2) set the option: curl_easy_setopt to tell libcurl how to operate. By using the appropriate parameters, you can use curl_easy_setopt to change the libcurl behavior. 3) execute: curl_easy_perform: used to execute the entire operation. 3. More complex examplesIn this example, an example named postit2.c demonstrates how to construct a post format in rfc1867 format and send it to the server. For details about the post format of rfc1867, see article 4: multipart/form-data. Through this example, we can find that postit2.c and Basic Use CasesThe structure is the same, but some content is added: There are more curl_formadd and several curl_easy_setopt options. We can The general libcurl programming is: Basic Use Case + other HTTP request content. The two are integrated into libcurl programming.  4. Conclusion:Easy interface is easy to use, but you must be familiar with the meaning of the options using the curl_easy_setopt function and the basic HTTP protocol content.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.