91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 8KB
    文件類型: .7z
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-05-16
  • 語(yǔ)言: C/C++
  • 標(biāo)簽: curl封裝??

資源簡(jiǎn)介

對(duì)libcurl進(jìn)行的封裝,非常好用

資源截圖

代碼片段和文件信息

//?http_request.cpp?:?定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
#include?“stdafx.h“
#include?“HttpRequest.h“
#include?
#include?

class?DownCallbackClass
{
public:
DownCallbackClass()?:m_down_finished(false)?{}
~DownCallbackClass()?{}
public:
void?DownResultCallback(int?id?bool?success?const?std::string&?data)
{
m_down_finished?=?true;
}
int?down_callback(double?total_size?double?downloaded_size?void*?userdata)
{
long?tmp?=?static_cast(downloaded_size?/?total_size?*?100);
printf(“\r下載進(jìn)度%d“?tmp);
return?0;
}
bool?IsDownFinished(void)?{?return?m_down_finished;?}
private:
bool?m_down_finished;
};

class?MyResultClass
{
public:
MyResultClass()?:?m_request_finished(false)?{?}
~MyResultClass()?{?}

public:
void?MyRequestResultCallback(int?id?bool?success?const?std::string&?data)
{
if?(success)
{
std::ofstream?outfile;
outfile.open(“baidu.html“?std::ios_base::binary?|?std::ios_base::trunc);
if?(outfile.good())?outfile.write(data.c_str()?data.size());
}
m_request_finished?=?true;
}
bool?IsRequestFinish(void)?{?return?m_request_finished;?}
private:
bool?m_request_finished;
};

int?_tmain(int?argc?_TCHAR*?argv[])
{
MyResultClass?mc;

HttpRequest?request;
request.SetRequestUrl(“http://www.biquge.com/21_21470“);
request.SetResultCallback(std::bind(&MyResultClass::MyRequestResultCallback?&mc?std::placeholders::_1?std::placeholders::_2?std::placeholders::_3));
request.SetRequestHeader(“User-Agent:Mozilla/4.04[en](Win95;I;Nav)“);

HANDLE?hRequest?=?request.PerformRequest(HttpRequest::REQUEST_ASYNC);
if?(hRequest)
{
while?(mc.IsRequestFinish()?==?false)?Sleep(300);
long?http_code;
if?(request.GetHttpCode(hRequest?&http_code))
std::cout?<
std::string?header;
if?(request.GetReceiveHeader(hRequest?&header))
{
std::cout?< }
std::string?content;
if?(request.GetReceiveContent(hRequest?&content))
{
std::cout?< }

HttpRequest::Close(hRequest);
}

HttpDownloader?download;
DownCallbackClass?dc;
const?char*?down_url?=?“http://dlsw.baidu.com/sw-search-sp/soft/71/10998/OfflineBaiduPlayer_151_V4.1.2.263.1432003947.exe“;
const?char*?down_file?=?“BaiduPlayer.exe“;

download.SetDownloadUrl(down_url);
download.SetProgressCallback(std::bind(&DownCallbackClass::down_callback?&dc?std::placeholders::_1?std::placeholders::_2?std::placeholders::_3));
download.SetResultCallback(std::bind(&DownCallbackClass::DownResultCallback?&dc?std::placeholders::_1?std::placeholders::_2?std::placeholders::_3));
download.DownloadFile(down_file);
HANDLE?hDownload?=?download.StartDownload(HttpDownloader::DOWN_ASYNC);
if?(hDownload)
{
while?(dc.IsDownFinished()?==?false)
{
Sleep(300);
}
//to?do?download?finish?clean?up
HttpDownloader::Close(hDownload);
}
getchar();
return?0;

評(píng)論

共有 條評(píng)論

相關(guān)資源