标签:android blog tar ext get int
1、cocos2d-x3.0 win7 64位 vs2012
1、添加libNetwork库,方法参照http://blog.csdn.net/st75033562/article/details/23303223中的添加库的方法,最好也把这里面的提到的3个库也给添加了。
2、添加链接:右击项目->属性->连接器->输入->附加依赖项->添加(libNetWork.lib、libExtensions.lib、libcurl_imp.lib)
#include "network/HttpClient.h" #include "network/HttpRequest.h"
USING_NS_CC; using namespace network;
1、发送数据
HttpClient* httpClient = HttpClient::getInstance(); HttpRequest* httpReq =new HttpRequest();
httpReq->setRequestType(HttpRequest::Type::GET); httpReq->setUrl("http://www.baidu.com/"); httpReq->setResponseCallback(this,SEL_HttpResponse(&HelloWorld::httpReqFinished)); httpReq->setTag("FirstNet"); httpClient->setTimeoutForConnect(300); httpClient->send(httpReq); httpReq->release();
2、回调解析
void HelloWorld::httpReqFinished(Node* node,CCObject* obj){ HttpResponse* response = (HttpResponse*)obj; if (!response->isSucceed()) { log("Receive Error! %s\n",response->getErrorBuffer()); return ; } const char* tag = response->getHttpRequest()->getTag(); if ( 0 == strcmp("FirstNet",tag)) { std::vector<char> *data = response->getResponseData(); int data_length = data->size(); std::string res; for (int i = 0;i<data_length;++i) { res+=(*data)[i]; } res+=‘\0‘; log("==========%s",res.c_str()); } }
1、需要在Android.mk添加
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static
$(call import-module,network)
cocos2d-x HttpClient,布布扣,bubuko.com
标签:android blog tar ext get int
原文地址:http://www.cnblogs.com/xhg986/p/3712144.html