Hot Door CORE Forum

Full Version: InternetGET/InternetPOST
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Am I correct in assuming that InternetGET and InternetPOST could be used by a plugin to do things such as communicate with a database at the home web site to check if it's the current version?

If so, what do I need to ask my ISP to set up for me (my intuition tells me it just may be SQL-related), and what specifically do I need to study to learn to use this function? A bit of sample code for something like a current-version inquiry would be very helpful, if that's part of what this class does.

Thanks -- Rick
Either of those classes simply performs a HTTP query (GET or POST) using the operating system's networking libraries. For example, if you use your web browser to go to "", you will see that the DynDNS server is kind enough to tell you your public IP address (i.e. the output is "Current IP Address:"). Using either class to query that same URL will allow you to retrieve the same exact string that your web browser showed, only from within a plugin of course.

So you need a web server and some content to serve up for either class to be of any use. How to do that is beyond the scope of the CORE forum, so you'll have to do a Google search for getting started with web development.
Thanks, Garrett. I knew it went beyond the scope of CORE, so I appreciate your steering me in the right direction.
Call me Nemo, but sometimes I'm often sure I can do things and later find that I can't. I'm trying to add an InternetGET to my preferences class, to alert the user if there's an update available.

My prefs class contains this, plus the callback functions:

    hdi::core::InternetGET iGET(hid::core::InternetGET("",HDI_CORE_CALLBACK(sansa::thePrefs, this, verifyVersionOKCB), HDI_CORE_CALLBACK(sansa::thePrefs, this, verifyVersionFailCB)); // my prefs class resides within a namespace

I must have tried fifty variations to create the InternetGET without success, noting that empty InternetGET objects cannot be constructed. Xcode continually scolds me about this class having a private default constructor. Once it's properly created, I understand that I should call its run() function to do the PHP query, then the callback will call the content() function to get the query result. If I find it sometimes takes a while, I'd like to make it asynchronous. Actually, asynchronous sounds like a better approach, regardless.

What is the proper syntax for this? This isn't quite as straightforward as making a dialog's button go to a URL.

Many thanks -- Rick

Edit: I later tried creating it in my main Plugin class as a test. Still stumped. I'll work through any namespace issues of my own making later, but it would be much easier if I first knew the correct syntax to get started. Confused
If you want an asynchronous InternetGET/POST object, you must allocate it on the heap rather than the stack, as (due to the asynchronicity) the object's lifespan must last longer than the current function call. To accomplish this, the InternetGET/POST class provides a static `Async()` method, which returns a pointer to a properly allocated InternetGET/POST object.

hdi::core::InternetGET* iGET = hdi::core::InternetGET::Async(<your arguments>);

And be sure to call the C++ `delete` operator on `iGET` before plugin shutdown. See the docs for the `Async()` method for other notes.
The GET function is working great! Now I need to send and receive POST data. I understand that the data sent is a DictionaryPref, but how will my PHP script understand it without CORE on the server? Will it arrive in JSON format? And for a PHP script to send information back to the plugin, is a JSON object best, or is it complicated to format it as a DictionaryPref again? Thanks a ton in advance.
A DictionaryPref is really just a key-value data structure, which is how HTTP POST data must be transmitted anyway. PHP will then perform its standard process to turn it into key-value data again, stored inside the $_POST variable.

You can send back whatever data you'd like in whatever format, as it's your responsibility to handle the content of the HTTP response. JSON isn't a bad idea, as you can use hdi::core::PrefData::parse() to process it.
Thanks, Garrett. I really appreciate your meaningful explanations.
Everything transfers as expected -- the data sent was interpreted correctly by the server and the JSON array returned was parsed into an std::auto_ptr<hdi::core::PrefData>, which seems to be a valid object since I can "stringify" it into the same string that went into it and isEmpty returns false.

The test data I parsed is:


Is there a straightforward way to copy or move PrefData into a DictionaryPref where I can work with it by key/value pairs? Thanks! Undecided
(10-01-2016 06:35 PM)Rick Johnson Wrote: [ -> ]Is there a straightforward way to copy or move PrefData into a DictionaryPref where I can work with it by key/value pairs? Thanks! Undecided

DictionaryPref inherits from PrefData, so you can simply cast the PrefData pointer to a DictionaryPref pointer. To be safe, don't forget to check the PrefData::dataType() method to be sure you're casting to the right subclass.
Pages: 1 2
Reference URL's