cocos2d-x 网络编程Curl

cocos2d-x 网络编程Curl,第1张

概述1 CURLcode curl_global_init(long flags);  描述:  这个函数只能用一次。(其实在调用curl_global_cleanup 函数后仍然可再用)  如果这个函数在curl_easy_init函数调用时还没调用,它讲由libcurl库自动完成。  参数:flags  CURL_GLOBAL_ALL    //初始化所有的可能的调用。  CURL_GLOBAL_ 1 CURLcode curl_global_init(long flags);

描述:
这个函数只能用一次。(其实在调用curl_global_cleanup 函数后仍然可再用)
如果这个函数在curl_easy_init函数调用时还没调用,它讲由libcurl库自动完成。
参数:flags
CURL_GLOBAL_ALL //初始化所有的可能的调用。
CURL_GLOBAL_SSL //初始化支持 安全套接字层。
CURL_GLOBAL_WIN32 //初始化win32套接字库。
CURL_GLOBAL_nothing //没有额外的初始化。
2 voID curl_global_cleanup(voID);
描述:在结束libcurl使用的时候,用来对curl_global_init做的工作清理。类似于close的函数。
3 char *curl_version( );
描述: 打印当前libcurl库的版本。
4 CURL *curl_easy_init( );
描述:
curl_easy_init用来初始化一个CURL的指针(有些像返回file类型的指针一样). 相应的在调用结束时要用curl_easy_cleanup函数清理.
一般curl_easy_init意味着一个会话的开始. 它的返回值一般都用在easy系列的函数中.
5 voID curl_easy_cleanup(CURL *handle);
这个调用用来结束一个会话.与curl_easy_init配合着用.
参数:
CURL类型的指针.
6 CURLcode curl_easy_setopt(CURL *handle,CURLoption option,parameter);
描述: 这个函数最重要了.几乎所有的curl 程序都要频繁的使用它.
它告诉curl库.程序将有如何的行为. 比如要查看一个网页的HTML代码等.
(这个函数有些像ioctl函数)
1 CURL类型的指针
2 各种CURLoption类型的选项.(都在curl.h库里有定义,man 也可以查看到)
3 parameter 这个参数 既可以是个函数的指针,也可以是某个对象的指针,也可以是个long型的变量.它用什么这取决于第二个参数.
CURLoption 这个参数的取值很多.具体的可以查看man手册.
7 CURLcode curl_easy_perform(CURL *handle);
描述:这个函数在初始化CURL类型的指针 以及curl_easy_setopt完成后调用. 就像字面的意思所说perform就像是个舞台.让我们设置的
option 运作起来.

CURL类型的指针


例子:

staticboolisLogin; CurlTest::Curltest() { cclabelTTF*label=cclabelTTF::create("CurlTest","Arial",28); addChild(label,0); label->setposition(ccp(VisibleRect::center().x,VisibleRect::top().y-50)); settouchEnabled(true); //createalabeltodisplaythetipstring m_pLabel=cclabelTTF::create("touchthescreentoconnect",22); m_pLabel->setposition(VisibleRect::center()); addChild(m_pLabel,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> m_pLabel->retain(); isLogin=false; } //thetestcodeis //http://curl.haxx.se/mail/lib-2009-12/0071.HTML voIDCurlTest::cctouchesEnded(CCSet*ptouches,CCEvent*pEvent) CURL*curl; CURLcoderes; charbuffer[10]; stringstrHTML; stringstrRetData=""; curl=curl_easy_init(); if(curl) { curl_easy_setopt(curl,CURLOPT_URL,"http://localhost/mobTest.PHP?user=cistudio&password=123"); curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,httpWriteString); //对认证证书来源的检查,0表示阻止对证书的合法性的检查。 //从证书中检查SSL加密算法是否存在 //模拟用户使用的浏览器,在http请求中包含一个”user-agent”头的字符串。 "Mozilla/4.0(compatible;MSie8.0;windowsNT5.0)"); //curl_easy_setopt(curl,CURLOPT_cookiefile,"cookiefile.txt"); //将登录信息记录并生成到一个cookies文件中 "cookiefile.txt"); //获取的信息以文件流的形式返回,而不是直接输出。 res=curl_easy_perform(curl); /*alwayscleanuP*/ curl_easy_cleanup(curl); if(res==CURLE_OK) m_pLabel->setString("0response"); strRetData=strHTML; cclOG("httpgetstring,ret:%s",strRetData.c_str()); } else sprintf(buffer,"code:%i",res); m_pLabel->setString(buffer); m_pLabel->setString("nocurl"); size_tCurlTest::httpWriteString(uint8_t*ptr,size_tsize,87); Font-weight:bold; background-color:inherit">size_tnumber,voID*stream) chartmpStr[10]; sprintf(tmpStr,"%s",ptr); if(tmpStr=="OK"){ true; }else{ isLogin=false; CURL*curl; CURLcoderes; "http://localhost/isLoginTest.PHP"); true); //对认证证书来源的检查,0表示阻止对证书的合法性的检查。 //从证书中检查SSL加密算法是否存在 //模拟用户使用的浏览器,在http请求中包含一个”user-agent”头的字符串。 "Mozilla/4.0(compatible;MSie8.0;windowsNT5.0)"); //读取cookies中的信息供给服务器调用 "cookiefile.txt"); cclog("completesgetLoginState"); cclog("%s%1d",ptr,number); returnsize*number;//这里一定要返回实际返回的字节数 size_tCurlTest::getLoginState(uint8_t*ptr,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cclog("%s",0); background-color:inherit">//这里一定要返回实际返回的字节数 CurlTest::~Curltest() m_pLabel->release(); voIDCurlTestScene::runThistest() cclayer*pLayer=newCurltest(); addChild(pLayer); CCDirector::sharedDirector()->replaceScene(this); pLayer->release(); } 总结

以上是内存溢出为你收集整理的cocos2d-x 网络编程Curl全部内容,希望文章能够帮你解决cocos2d-x 网络编程Curl所遇到的程序开发问题。

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

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

原文地址: http://www.outofmemory.cn/web/1002548.html

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

发表评论

登录后才能评论

评论列表(0条)

保存