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; margin:0px; padding:0px; border:none; 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();
- }