需要加
#include "cocos-ext.h"
USING_NS_CC_EXT;

void HelloWorld::start()
{
    CCLog("%s",__FUNCTION__);
    CCHttpRequest *request=new CCHttpRequest();
    CCEditBox *box=(CCEditBox *)this->getChildByTag(1);
    CCEditBox *box2=(CCEditBox *)this->getChildByTag(2);
    request->setUrl(URL);
    request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpPost);
    CCString *string=CCString::createWithFormat("user_name=%s&user_password=%s",box->getText(),box2->getText());
    request->setRequestData(string->getCString(), strlen(string->getCString()));
    request->setResponseCallback(this, httpresponse_selector(HelloWorld::HttpResponse));
    CCHttpClient::getInstance()->send(request);
}
void HelloWorld::HttpResponse(CCHttpClient* client, CCHttpResponse* response)
{
    if (!response->isSucceed()) {
        CCLOG("%s",response->getErrorBuffer());
    }
    else
    {
        std::vector<char>*victor = response->getResponseData();
        char *datastring =new char((*victor).size()+1);
        for (int i=0; i<(*victor).size(); i++) {
            datastring[i]=(*victor)[i];
        }
        datastring[(*victor).size()]='\0';
        CCLOG("%s",datastring);
        
    }
}



☟☟可点击下方广告支持一下☟☟

最后修改:1970 年 01 月 01 日
请我喝杯可乐,请随意打赏: ☞已打赏列表