找回密码
 立即注册
搜索

本文来自

iOS开发交流区

iOS开发交流区

人已关注

请添加对本版块的简短描述

cocos2dx2.2.6 ios http请求

[复制链接]

1

主题

1

帖子

32

积分

新手上路

Rank: 1

积分
32
QQ
413 sonict8 发表于 2018-5-31 13:45:26
void XXX::onHttpRequest()
{
CCHttpRequest* request = new CCHttpRequest();
if (request)
{
request->setUrl("XXX");
request->setRequestType(CCHttpRequest::kHttpPost);
request->setResponseCallback(this, httpresponse_selector(LogonScene::onHttpRequestCompletedClientVersion));

// write the post data
char m_postData[128];
sprintf(m_postData, "kindid=%d", GAME_KINDID);
const char* postData = m_postData;
request->setRequestData(postData, strlen(postData));

request->setTag("POST ClientVersion");
CCHttpClient::getInstance()->send(request);
request->release();
}
}

void XXX::onHttpRequestCompleted(cocos2d::extension::CCHttpClient *sender, cocos2d::extension::CCHttpResponse *response)
{
if (!response)
{
return;
}

// You can get original request type from: response->request->reqType
if (0 != strlen(response->getHttpRequest()->getTag()))
{
CCLog("%s completed", response->getHttpRequest()->getTag());
}

int statusCode = response->getResponseCode();
}


Android环境下一切正常,IOS环境下 statusCode=-1,http请求失败,xcode中info中 App Transport Security Settings 下 Allows Arbitrary Loads 已经设置为 YES,求问大神这是怎么回事




上一篇:collectionviewcell 点击效果
下一篇:segue转场界面卡死问题
楼主热帖
87355629 发表于 2018-5-31 15:27:35
void XXX::onHttpRequest()
{
    CCHttpRequest* request = new CCHttpRequest();
    if (request)
    {
        request->setUrl("XXX");
        request->setRequestType(CCHttpRequest::kHttpPost);
        request->setResponseCallback(this, httpresponse_selector(LogonScene::onHttpRequestCompletedClientVersion));

        // write the post data
        char m_postData[128];
        sprintf(m_postData, "kindid=%d", GAME_KINDID);
        const char* postData = m_postData;
        request->setRequestData(postData, strlen(postData));

        request->setTag("POST ClientVersion");
        CCHttpClient::getInstance()->send(request);
        request->release();
    }
}

void XXX::onHttpRequestCompleted(cocos2d::extension::CCHttpClient *sender, cocos2d::extension::CCHttpResponse *response)
{
    if (!response)
    {
        return;
    }

    // You can get original request type from: response->request->reqType
    if (0 != strlen(response->getHttpRequest()->getTag()))
    {
        CCLog("%s completed", response->getHttpRequest()->getTag());
    }

    int statusCode = response->getResponseCode();
    }
   
   
    Android环境下一切正常,IOS环境下 statusCode=-1,http请求失败,xcode中info中 App Transport Security Settings 下 Allows Arbitrary Loads 已经设置为 YES,求问大神这是怎么回事
回复

使用道具 举报

taylor_tao 发表于 2018-5-31 19:26:25

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则