[From http to AWS] [4] Using libcurl with OpenSSL support

Source: Internet
Author: User
Tags perl script

In fact, libcurl has binding in many languages. I prefer C ++, but since curlpp is too troublesome, I directly use libcurl in C language.

> Build OpenSSL

Download OpenSSL from www.openssl.org and install the Perl Environment

1> perl Configure VC-WIN32 --prefix=c:/some/openssl/dir

2> ms\do_ms
3> nmake -f ms\nt.mak (for static library)

Or

3> nmake -f ms\ntdll.mak (for DLL)

> Build libcurl

Download libcurl from http://curl.haxx.se and open vc6curl. DSW compilation.

Do you have use_ssleay and use_openssl in Preprocessor?

 

>> Certification

Http://curl.haxx.se/docs/sslcerts.html


Libcurlloads A certdata.txt file from mozillaand generates the desired *. CRT file.

'Http: // mxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt? Raw = 1'

Run Perl script to generate a ca-bundle.crt using OpenSSL, and then configure curlopt_cainfo:


// Run this script to generate the ca-bundle.crt

S: \ Components \ cplusplus \ curl-7.20.0 \ Lib \ mk-ca-bundle.pl

If the configuration fails, curle_ssl_cacert is returned when you access HTTPS.

 

> Libcurl

In the simplest example, retrieve the content of the http://curl.haxx.se/docs/thanks.html page and write it to a local file.
Although it is better than Python's urllib.

For easy interface, the basic steps are as follows:

Initialize libcurl

Initialize easy interface

Set the required Option

Execute request

Clear easy interface

Clear libcurl


Code:

// Configure //--------------------------------------------------------------------------------------------------------

// Initialize libcurl

//

Curlcode return_code;

Return_code = curl_global_init (curl_global_win32 );

If (curle_ OK! = Return_code) return;

// Get easy handle

//

Curl * easy_handle = curl_easy_init ();

If (null = easy_handle)

{

Curl_global_cleanup ();

Return;

}

// Open a local file

//

File * fp = fopen ("C: \ thanks.html", "AB + ");
// Set easy handle properties

//

Curl_easy_setopt (easy_handle, curlopt_url, "http://curl.haxx.se/docs/thanks.html ");

Curl_easy_setopt (easy_handle, curlopt_writefunction, & process_data );

Curl_easy_setopt (easy_handle, curlopt_writedata, FP );

// Perform request

//

Curl_easy_perform (easy_handle );
// Close file

//

Fclose (FP );

// Clean up curl

//

Curl_easy_cleanup (easy_handle );

Curl_global_cleanup ();

// Configure //--------------------------------------------------------------------------------------------------------

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.