Hey, I’m having an issue attempting to community php from server however I don’t suppose the code is mistaken are you keen to assist me?
that is my code
cocos2d::community::HttpRequest* request = new cocos2d::community::HttpRequest();
request->setUrl( “https://www.doniwahyudi.ga/get.php” );
request->setRequestType(cocos2d::community::HttpRequest::Kind::GET);
request->setResponseCallback(CC_CALLBACK_2(HelloWorld::onHttpRequestCompleted, this));
request->setTag(“GET check”);
cocos2d::community::HttpClient::getInstance()->ship(request);
request->launch();
void HelloWorld::onHttpRequestCompleted(cocos2d::community::HttpClient* sender, cocos2d::community::HttpResponse* response)
{
// The info will probably be positioned within the buffer.
std::vector<char>* buffer = response->getResponseData();
char* concatenated = (char*)malloc(buffer->measurement() + 1);
std::string s2(buffer->start(), buffer->finish());
strcpy(concatenated, s2.c_str());
// JSON Parser
Json* json = Json_create(concatenated);
int test1 = Json_getInt(json, "a", -1);
const char* test2 = Json_getString(json, "b", "default");
float test3 = Json_getFloat(json, "c", -1.0f);
// View the console
log("HTTP Response : key a : %i", test1);
log("HTTP Response : key b : %s", test2);
log("HTTP Response : key c : %f", test3);
// Delete the JSON object
Json_dispose(json);
if (response->getResponseCode() == 200)
{
log("Succeeded");
return;
}
else
{
log("Failed");
}
}