08-05-2015, 03:58 PM
There are currently no sample projects that include this functionality, but here is a quick code sample that should work.
Add the following to the header file of the Plugin class in the Skeleton sample project:
Then add the following to the definition of the postStartup() member function in the implementation file of the Plugin class in the Skeleton sample project:
Finally, add the following somewhere in the implementation file of the Plugin class in the Skeleton sample project:
Once you compile and run the Skeleton project, you will see the same HTML code printed in the debugger as if you had visited http://checkip.dyndns.com/ (in your browser). If the URL cannot be successfully loaded, then the failure callback will execute instead and you will see the error string printed in the debugger.
On Windows you might have to use OutputDebugString() instead of std::cout.
Add the following to the header file of the Plugin class in the Skeleton sample project:
Code:
hdi::core::InternetGET* ipChecker;
void ipCheckSuccess();
void ipCheckFailure();
Then add the following to the definition of the postStartup() member function in the implementation file of the Plugin class in the Skeleton sample project:
Code:
this->ipChecker = hdi::core::InternetGET::Async(
"http://checkip.dyndns.com/",
HDI_CORE_CALLBACK(skel::Plugin, this, ipCheckSuccess),
HDI_CORE_CALLBACK(skel::Plugin, this, ipCheckFailure)
);
this->ipChecker->run();
Finally, add the following somewhere in the implementation file of the Plugin class in the Skeleton sample project:
Code:
void skel::Plugin::ipCheckSuccess()
{
if(!this->ipChecker)
return;
std::cout << this->ipChecker->content() << "\n";
}
void skel::Plugin::ipCheckFailure()
{
if(!this->ipChecker)
return;
std::cout << this->ipChecker->error() << "\n";
}
Once you compile and run the Skeleton project, you will see the same HTML code printed in the debugger as if you had visited http://checkip.dyndns.com/ (in your browser). If the URL cannot be successfully loaded, then the failure callback will execute instead and you will see the error string printed in the debugger.
On Windows you might have to use OutputDebugString() instead of std::cout.