Unable to connect to server using HttpRequest

Cocos2d-x C++ Networking
  • sbsimar023
    Likes 0

    Problem Description

    I have followed the exact same steps a mentioned in the GET data from server video but I receive response code as -1

    init function of Helloworld.cpp : 

        network::HttpRequest *request = new network::HttpRequest();
        request->setUrl("http://www.sonarlearning.co.uk/extras/cocostutorial/get.php");
        request->setRequestType(network::HttpRequest::Type::GET);
        request->setResponseCallback(CC_CALLBACK_2(HelloWorld::onHttpRequestCompleted,this));
        network::HttpClient::getInstance()->send(request);
        request->release();
        return true;
    }


    void HelloWorld::onHttpRequestCompleted(network::HttpClient *sender, network::HttpResponse *response)
    {
       
            if ( response->getResponseCode() == 200 )
            {
                printf( "Succeeded" );
                return;
            }
            else
            {
                printf("Failed");
            }
    }

Login to reply