curl.so php,libcurl升级后找不到libcurl.so.3解决之法_PHP教程

#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.bKjia.c0m";

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值