HTTP请求实现
把以下代码拷贝到新创建的project中就能看到效果
HelloWorldScene.h
#include "cocos2d.h"
/*记得要引头文件*/
#include "extensions/cocos-ext.h"
#include "network/HttpClient.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace network;
class HelloWorld : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
void onMenuGetTestClicked(Ref* sender);
void onMenuPostBinaryTestClicked(Ref* sender);
//Http Response Callback
void onHttpRequestCompleted(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response);
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
};
HelloWorldScene.cpp
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5061672.html,如需转载请自行联系原作者