cocos2dx 使用curl
来源:互联网 发布:mac怎样修改快捷键 编辑:程序博客网 时间:2024/05/19 05:40
#include "HelloWorldScene.h"#include "AppMacros.h"#include "pthread.h" #include "Json.h"#include "curl.h"USING_NS_CC;CCScene* HelloWorld::scene(){ // 'scene' is an autorelease object CCScene *scene = CCScene::create(); // 'layer' is an autorelease object HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene;}// on "init" you need to initialize your instance//静态函数size_t HelloWorld::writehtml(uint8_t* ptr,size_t size,size_t number,void *stream) { CCString* a=CCString::createWithFormat("%s",ptr); std::string str1=a->getCString();const char* _ch = str1.c_str();CCLog(_ch);Json* myjson = Json_create(_ch);const char* _ch1= Json_getString(myjson,"name","");CCLog(_ch1);return size*number;//这里一定要返回实际返回的字节数 }bool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; }#if 1CURL *curl; CURLcode res; string cc; curl=curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.148/phpProject/test1.php?user=wu"); //设置请求的地址 curl_easy_setopt(curl, CURLOPT_POST, true); //设置数据类型string caozuo="";curl_easy_setopt(curl, CURLOPT_POSTFIELDS,caozuo.c_str()); //将操作代码,和连接的网站组合,一起发送! curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,&HelloWorld::writehtml); //数据处理回调函数 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cc);//缓冲的内存 curl_easy_setopt(curl,CURLOPT_TIMEOUT_MS,5000); //设置连接超时时间 res = curl_easy_perform(curl); if(res==CURLE_OK) { CCLog("ok");} curl_easy_cleanup(curl); } else { CCLog("curl is null"); } #endifreturn true;}void HelloWorld::menuCloseCallback(CCObject* pSender){#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");#else#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0);#endif#endif}bool HelloWorld::ccTouchBegan( CCTouch* touch, CCEvent* event ){CCLog("touchBegan1");return true;}
<?php header("Access-Control-Allow-Origin: *"); if(isset($_GET['user'])){ //echo "hello world"; $_arr = array('id' => 1, 'name' => 'wuhongxing', 'age' => 20, 'sex' =>0); $_arr = json_encode($_arr); echo $_arr; } else{ echo "请先登录"; } ?>
0 0
- cocos2dx 使用curl
- cocos2dx之curl下载
- cocos2dx中 curl
- cocos2dx 3.3 curl配置
- cocos2dx网络传输之CURL
- curl使用
- Curl 使用
- curl使用
- curl使用
- curl使用
- curl使用
- curl使用
- curl 使用
- curl 使用
- curl使用
- CURL使用
- curl使用
- curl使用
- windbg分析BSOD dump文件实战
- 指针使用前应先初始化
- 获取Cocosdx精灵的像素点的RGBA
- 【Architecture】分布式 V.S. 集群
- HDOJ 2063 过山车 ——二分图最大匹配(以邻接矩阵,邻接表为数据结构的匈牙利算法)
- cocos2dx 使用curl
- android webView加载phongap开发出的html5 数据无法加载出来
- VC HID开发笔记
- mysql基于查询结果批量插入和更新
- linux上实用命令集锦 (亲测Ubuntu12.04)
- xcode armv7 armv7s arm64 类型, 区分, 概念
- cell上加label 按住cell时label背景颜色变透明
- Oracle表空间管理维护
- 实例变量和属性 区别