Solution to libcurl. so.3 not found after libcurl upgrade

Source: Internet
Author: User
Tags curl http post int size

The system installs libcurl 7.19 and the compiled dynamic library is libcurl. so.4.

Your program is compiled in libcurl 7.15 and uses libcurl. so.3. You just need to make a soft link:
Perform the following operations based on your 32-bit or 64-bit systems:

The code is as follows: Copy code

Cd/usr/lib or cd/usr/lib64
Ln-s libcurl. so.4 libcurl. so.3


The main function of libcurl is to connect and communicate with different servers through different protocols ~ That is to say, sockPHP supports libcurl (which allows you to connect to and communicate with different servers using different protocols )., Libcurl currently supports http, https, ftp, gopher, telnet, dict, file, and ldap protocols. Libcurl also supports HTTPS Certificate authorization, http post, http put, FTP upload (of course, you can also use PHP ftp extension), HTTP Basic form Upload, proxy, cookies, and user authentication.
 

Here is a simple code example:
Note:
1. The key is to set option in the curl_easy_setopt function. You can set many options, such as ftp, http, get, and post. Set options based on actual usage.

2. Determine the retrieved data, for example, to download an http File. If the file does not exist, process it. Because writer can fill the buf with webpage content such as 404 not found and cannot regard this content as the file content, it is necessary to determine the code returned by the http web for judgment.

3. I have a problem, that is, I want to get the specific name of filename on the server. verbose debugging has returned, but I tried many options during getinfo, however, the option for storing the real server file name is not found. If you have any questions, please let me know. Thank you!

The code is as follows: Copy code


# Include "curl/curl. h"
# Pragma comment (lib, "libcurl. lib ")

Long writer (void * data, int size, int nmemb, string & content );
Bool CurlInit (CURL * & curl, const char * url, string & content );
Bool GetURLDataBycurl (const char * URL, string & content );

Void main ()
{
Char * url = "http://www.111cn.net ";
String content;
If (GetURLDataBycurl (url, content ))
    {
Printf ("% sn", content );

    }
Getchar ();
}

Bool CurlInit (CURL * & curl, const char * url, string & content)
{
CURLcode code;
String error;
Curl = curl_easy_init ();
If (curl = NULL)
    {
Printf ("Failed to create CURL connectionn ");
Return false;
    }
Code = curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, error );
If (code! = CURLE_ OK)
    {
Printf ("Failed to set error buffer [% d] n", code );
Return false;
    }
Curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L );
Code = curl_easy_setopt (curl, CURLOPT_URL, url );
If (code! = CURLE_ OK)
    {
Printf ("Failed to set URL [% s] n", error );
Return false;
    }
Code = curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1 );
If (code! = CURLE_ OK)
    {
Printf ("Failed to set redirect option [% s] n", error );
Return false;
    }
Code = curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writer );
If (code! = CURLE_ OK)
    {
Printf ("Failed to set writer [% s] n", error );
Return false;
    }
Code = curl_easy_setopt (curl, CURLOPT_WRITEDATA, & content );
If (code! = CURLE_ OK)
    {
Printf ("Failed to set write data [% s] n", error );
Return false;
    }
Return true;
}

Long writer (void * data, int size, int nmemb, string & content)
{
Long sizes = size * nmemb;
String temp (data, sizes );
Content + = temp;
Return sizes;
}

Bool GetURLDataBycurl (const char * URL, string & content)
{
CURL * curl = NULL;
CURLcode code;
String error;

Code = curl_global_init (CURL_GLOBAL_DEFAULT );
If (code! = CURLE_ OK)
    {
Printf ("Failed to global init default [% d] n", code );
Return false;
    }
   
If (! CurlInit (curl, URL, content ))
    {
Printf ("Failed to global init default [% d] n ");
Return PM_FALSE;
    }
Code = curl_easy_perform (curl );
If (code! = CURLE_ OK)
    {
Printf ("Failed to get '% s' [% s] n", URL, error );
Return false;
    }
Long retcode = 0;
Code = curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, & retcode );
If (code = CURLE_ OK) & retcode = 200)
    {
Double length = 0;
Code = curl_easy_getinfo (curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, & length );
Printf ("% d", retcode );
FILE * file = fopen ("1.gif"," wb ");
Fseek (file, 0, SEEK_SET );
Fwrite (content. c_str (), 1, length, file );
Fclose (file );

// Struct curl_slist * list;
// Code = curl_easy_getinfo (curl, CURLINFO_COOKIELIST, & list );
// Curl_slist_free_all (list );

Return true;
    }
Else
    {
// Debug1 ("% s n", getStatusCode (retcode ));
Return false;
    }
Curl_easy_cleanup (curl );
Return false;
}

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.