Hot Door CORE Forum
Collect information from web - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: Getting started (http://hotdoorcore.com/forum/forumdisplay.php?fid=6)
+--- Thread: Collect information from web (/showthread.php?tid=53)



Collect information from web - jun - 07-27-2015

I want to create a plug-ins which will need to validate the username and password in web, upon sucessful of login, it should collect address and images from the web. Huh


RE: Collect information from web - garrett - 07-27-2015

You can use our InternetGET and InternetPOST classes for this, which allow for both synchronous and asynchronous HTTP(S) GET and POST requests (respectively). A synchronous request will block the owning thread (so if you want/need to manage your own threads this is the way to go), and an asynchronous request will run in a background thread.


RE: Collect information from web - jun - 08-05-2015

(07-27-2015, 08:25 AM)garrett Wrote: You can use our InternetGET and InternetPOST classes for this, which allow for both synchronous and asynchronous HTTP(S) GET and POST requests (respectively). A synchronous request will block the owning thread (so if you want/need to manage your own threads this is the way to go), and an asynchronous request will run in a background thread.

Thanks for the input. But im currently facing issues in getting it running. Is there any sample available that I could refer for this.

Thank you.


RE: Collect information from web - garrett - 08-05-2015

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:
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.


RE: Collect information from web - Rick Johnson - 03-04-2017

Looking through the header notes I found "Asynchronous InternetGET objects must be allocated using operator new" and wondered if the first line of this example allocated as if "new" was somehow implicit:

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)
    );

If I change this to add "new" then I get a syntax error that Async is not a type. I can't create an empty instance and then add the Async info later:

Code:
this->ipChecker->Async(...

...because I cannot create an instance without including the parameters, and calling ->Async with the required parameters crashes at runtime. The example code first provided has worked well for me for both async POST and GET, but when a fluke at my web host caused a permissions error, all of my plugins crashed Illustrator in the HTTP call rather than fail gracefully as they did when the server was eventually shut down. I want to ensure that Async calls are done correctly, so any clarification would be very much appreciated.


RE: Collect information from web - garrett - 03-07-2017

It's implied that hdi::core::InternetGET::Async() uses operator new internally, because the other part of the function docs says "The responsibility for the memory of the returned InternetGET pointer lies with the caller, and it must not be deleted until after either the success or failure callbacks are called." I have just updated the docs to be more explicit in this regard.


RE: Collect information from web - Rick Johnson - 03-07-2017

Thanks, Garrett!