cocos2dx 使用curl

cocos2dx 使用curl,第1张

概述#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
#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 1	CURL *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");  	}  #endif		return 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 "请先登录";  }  ?> 
总结

以上是内存溢出为你收集整理的cocos2dx 使用curl全部内容,希望文章能够帮你解决cocos2dx 使用curl所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1010634.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存