文章2:Using The libcurl C Interface(重要)

来源:互联网 发布:农村淘宝报名有用吗 编辑:程序博客网 时间:2024/04/30 01:18

Using The libcurl C Interface

There's the tutorial to start with, read the tutorial to get a general in-depth grip of what libcurl programming is all about.

有一篇概述文章,阅读 the tutorial可以对于libcurl编程有一个深入的理解。

There are some example C source codes you can check out. They're not all-covering or even very extensive, but they might serve as a source of inspiration to start hacking.

另外,也可以在example C source codes学习libcurl。

Dig into the Symbols In Versions document to learn in which libcurl releases symbols were added or removed.

Windows developers using Microsoft Visual Studio, might enjoy:

  • Andrei Jakab's Using libcurl with SSH support in Visual Studio 2010 [PDF]
  • Rosso Salmanzadeh's Using libcurl in Visual Studio [PDF] guide.

Easy or Multi

The easy interface is a synchronous, efficient, quickly used and... yes, easy interface for file transfers. Numerous applications have been built using this.

The multi interface is the asynchronous brother in the family and it also offers multiple transfers using a single thread and more. Get a grip of how to work with it in the multi interface overview.

easy interface是同步、高效、方便使用的,并且easy interface用于文件传输。大量的应用程序都使用easy interface。

multi interface是异步的,提供了使用单个线程或多线程的多次传输。可以阅读 the multi interface overview来理解multi interface是如何工作的

The Easy interface

When using libcurl you init (libcurl - curl_global_init())your easy-session and get a handle, which you use as input to the following interface functions you use.

You continue by setting all the options you want in the upcoming transfer, most important among them is the URL itself. You might want to set some callbacks as well that will be called from the library when data is available etc.

When all is setup, you tell libcurl to perform the transfer. It will then do the entire operation and won't return until it is done or failed.

After the performance is made, you may get information about the transfer and then you cleanup the easy-session's handle and libcurl is entire off the hook!

在使用libcurl时,首先是初始化你的easy-session(简单对话)并获得一个handle,你可以使用这个handle作为接下来所用的接口函数的输入。

接下来,你设置在upcoming transfer(接下来的传输,实际上就是指:接下来的这次连接)中你想要的选项,这些选项中最重要的就是URL。你也可以设置一些用于数据处理的一些回调函数。

当这些都已经建立以后,你就可以执行这次transfer。它会执行所有操作,知道成功或者失败才会返回值。

 

 

See also the easy interface overview.

curl_easy_init() 
curl_easy_cleanup() 
curl_easy_setopt() 
curl_easy_perform() 
curl_easy_getinfo()

While the above functions are the main functions to use in the easy interface, there is a series of other helpful functions too including:

这些函数时在easy interface总经常用到的函数,还有一系列其他的有用的函数

 

curl_version()returns a pointer to the libcurl version stringcurl_getdate()converts a date string to time_tcurl_formadd()build multipart form-data postscurl_formfree()free a previously built form POSTcurl_slist_append()builds a linked listcurl_slist_free_all()frees a whole curl_slist as made with curl_slist_append()curl_easy_escape()URL encodes a stringcurl_easy_unescape()URL decodes a string

All man pages are included in every release archive, in three different formats: man page, HTML and pdf.

所有的说明文档都包含在每个发行版本里,有三种形式:man page,HTML和pdf




原创粉丝点击