Network connection status

Network connection status
0

#1

I want to determine the network connection status of the device. However, even if you shut down the network with the following code, I will get success. why? I want to know the right one.

cocos2d::network::HttpRequest *request = new cocos2d::network::HttpRequest();
request->setUrl(“https://www.google.com/get.php”);
request->setRequestType(cocos2d::network::HttpRequest::Type::GET);
request->setResponseCallback(CC_CALLBACK_2(HelloWorld::onHttpRequestCompleted, this));
cocos2d::network::HttpClient::getInstance()->send(request);
request->release();

void HelloWorld::onHttpRequestCompleted(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response)
{
std::vector *buffer = response->getResponseData();

printf("Get data: ");
for (unsigned int i = 0; i < buffer->size(); i++)
{
    printf("%c", (*buffer)[i]);
}
printf( "\n" );

if (200 != response->getResponseCode())
{
    printf("Succeeded");
    return;
}
else
{
    printf("Failed");
}

}


#2

I’m just reading this quick, but:
if the response is 404 --> succeeded (200 != 404)
if the response is 200 --> failed.


#3

I did it! Thanks to you.