About   |   Getting Started   |   Downloads   |   Documentation   |   Forum


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
InternetGET/InternetPOST
05-04-2016, 05:01 PM
Post: #1
InternetGET/InternetPOST
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
Find all posts by this user
Quote this message in a reply
05-04-2016, 06:50 PM
Post: #2
RE: InternetGET/InternetPOST
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 "http://checkip.dyndns.org", 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: xxx.xxx.xxx.xxx"). 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.
Find all posts by this user
Quote this message in a reply
05-05-2016, 10:20 AM
Post: #3
RE: InternetGET/InternetPOST
Thanks, Garrett. I knew it went beyond the scope of CORE, so I appreciate your steering me in the right direction.
Find all posts by this user
Quote this message in a reply
07-18-2016, 08:30 PM (This post was last modified: 07-19-2016 07:35 AM by Rick Johnson.)
Post: #4
RE: InternetGET/InternetPOST
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:

Code:
    hdi::core::InternetGET iGET(hid::core::InternetGET("http://HodorUsesCORE.org/version.php?p=126",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
Find all posts by this user
Quote this message in a reply
07-19-2016, 06:17 PM
Post: #5
RE: InternetGET/InternetPOST
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.

Code:
hdi::core::InternetGET* iGET = hdi::core::InternetGET::Async(<your arguments>);
if(iGET)
{
    iGET->run();
}

And be sure to call the C++ `delete` operator on `iGET` before plugin shutdown. See the docs for the `Async()` method for other notes.
Find all posts by this user
Quote this message in a reply
09-23-2016, 04:18 PM
Post: #6
RE: InternetGET/InternetPOST
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.
Find all posts by this user
Quote this message in a reply
09-29-2016, 09:26 AM
Post: #7
RE: InternetGET/InternetPOST
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.
Find all posts by this user
Quote this message in a reply
09-29-2016, 10:38 AM
Post: #8
RE: InternetGET/InternetPOST
Thanks, Garrett. I really appreciate your meaningful explanations.
Find all posts by this user
Quote this message in a reply
10-01-2016, 06:35 PM (This post was last modified: 10-02-2016 09:40 PM by Rick Johnson.)
Post: #9
RE: InternetGET/InternetPOST
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:

Code:
"{\"name\":\"Chewbacca\",\"number\":\"123.456\",\"other\":\"ABC123\"}"

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
Find all posts by this user
Quote this message in a reply
10-03-2016, 08:13 AM
Post: #10
RE: InternetGET/InternetPOST
(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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)