cocos2dx2.2.6 ios http请求

[复制链接]
190 3
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,求问大神这是怎么回事

举报 使用道具

回复

3 个评论

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

举报 使用道具

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

本版积分规则

ios.irunthink.com
搜索
热搜: iOS swift 下拉刷新

图文热点

更多

开发教程

更多

客服中心

400-800 周一至周日 9:30-17:30 仅收市话费

关注我们

  • 微信扫描
  • 关注微信
关于我们
关于我们
友情链接
联系我们
帮助中心
精贴推荐
源码上传
注册登录
服务支持
资源下载
关注我们
官方微博
官方空间
快速回复 返回顶部 返回列表