- #include "pthread.h"
- #pragma comment(lib,"libcurl_imp.lib")
- #pragma comment(lib,"pthreadVCE2.lib")
- #pragma comment(lib,"libExtensions.lib")
- void HelloWorld::onHttpRequestCompleted(CCHttpClient *pSender,CCHttpResponse *pResponse )
- {
- std::vector<char> *buffer = pResponse->getResponseData();
- char* buf = (char*)malloc(buffer->size());
- std::copy(buffer->begin(), buffer->end(), buf);
- std::string sFileName = "XX.png";
- FILE *fp = fopen(sFileName.c_str(),"wb+");
- fwrite(buf,1,buffer->size(),fp);
- fclose(fp);
- }
-
- bool HelloWorld::init()
- {
- bool bRet = false;
- do
- {
- CC_BREAK_IF(! CCLayer::init());
- CCHttpRequest* pRequest = new CCHttpRequest();
- pRequest->setUrl("http://img12.3lian.com/gaoqing02/06/56/13.jpg");
- pRequest->setRequestType(CCHttpRequest::kHttpGet);
- pRequest->setResponseCallback(this, httpresponse_selector(HelloWorld::onHttpRequestCompleted));
- CCHttpClient::getInstance()->send(pRequest);
- pRequest->release();
- bRet = true;
- } while (0);
- return bRet;
- }
OK最后附上本工程的下载地址需要的可以去下载看看或进行下扩展
本人郑重声明如下 一、本文来自CSDN博客,传送门: 二、All Rights Reserved. 任何个人或网站转载本文时不得移除本声明. 三、不得对文章进行修改,除非明确说明.同时欢迎大家评论转载和分享.