About   |   Getting Started   |   Downloads   |   Documentation   |   Forum


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collect information from web
07-27-2015, 04:07 AM
Post: #1
Collect information from web
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
Find all posts by this user
Quote this message in a reply
07-27-2015, 08:25 AM
Post: #2
RE: Collect information from web
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.
Find all posts by this user
Quote this message in a reply
08-05-2015, 04:18 AM
Post: #3
RE: Collect information from web
(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.
Find all posts by this user
Quote this message in a reply
08-05-2015, 03:58 PM
Post: #4
RE: Collect information from web
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.
Find all posts by this user
Quote this message in a reply
03-04-2017, 03:33 PM (This post was last modified: 03-05-2017 09:09 AM by Rick Johnson.)
Post: #5
RE: Collect information from web
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.
Find all posts by this user
Quote this message in a reply
03-07-2017, 12:23 PM
Post: #6
RE: Collect information from web
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.
Find all posts by this user
Quote this message in a reply
03-07-2017, 08:34 PM
Post: #7
RE: Collect information from web
Thanks, Garrett!
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


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