Results 1 to 2 of 2

Thread: Need ideas on implementing multi-https requests in my library

  1. #1
    Join Date
    Oct 2016
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Need ideas on implementing multi-https requests in my library

    Hi, I need your suggestions on an implementation problem I have. I'm coding an application that gets data from a site (not mine).

    I splitted the client and the library. The whole works this way (briefly):

    * the client queries the ApiRequest class for one of the site features and gets back an object for that feature, waiting for a signal from it; for instance:

    Qt Code:
    1. loginCheck = api->loginCheck();
    2. connect( loginCheck, SIGNAL(finished()), ... );
    3. connect( loginCheck, SIGNAL(parseError()), ... );
    4. connect( loginCheck, SIGNAL(requestError(QNetworkReply::NetworkError)), ... );
    To copy to clipboard, switch view to plain text mode 

    * ApiRequest is a static class instanced this way:

    Qt Code:
    1. ApiRequest::ApiRequest()
    2. {
    3. nam = new QNetworkAccessManager;
    4. requestHandler = new RequestHandler(nam);
    5. }
    To copy to clipboard, switch view to plain text mode 

    with a series of functions, like:

    Qt Code:
    1. LoginCheck * ApiRequest::loginCheck( )
    2. {
    3. ...
    4. QNetworkReply *reply;
    5. reply = requestHandler->getRequest( requestUrl );
    6.  
    7. LoginCheck * loginCheck( new LoginCheck( reply ) );
    8. return loginCheck;
    9. }
    To copy to clipboard, switch view to plain text mode 

    * RequestHandler returns a QNetworkReply for the request:

    Qt Code:
    1. QNetworkReply* RequestHandler::getRequest( const QString& url )
    2. {
    3. QUrl reqUrl( url );
    4. QNetworkRequest request( reqUrl );
    5. QNetworkReply* reply = nam->get( request );
    6. return reply;
    7. }
    To copy to clipboard, switch view to plain text mode 

    All this is working fine when each request needs only one QNetworkRequest. The problem is with the login feature that requires, in a row, GET, POST, REDIRECT, GET, REDIRECT, REDIRECT... I know, the site must be very dumb.

    The problem is that with current implementation the object returned from ApiRequest essentially parses the output from the first GET request, and can't build new requests itself. I could put the chain of requests in the client but I prefer avoiding this ugly solution.

    Do you have any suggestion? Do I have to rethink all the library?

    Thanks for your time.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Need ideas on implementing multi-https requests in my library

    When you create the LoginCheck instance, just also pass "this", i.e. the ApiRequest object.

    That way LoginCheck can initiate further requests.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 6th May 2014, 03:16
  2. Replies: 4
    Last Post: 30th July 2013, 10:33
  3. Replies: 0
    Last Post: 22nd October 2012, 12:39
  4. QT C++ Library for Multi Card Reader
    By georgeky in forum Jobs
    Replies: 0
    Last Post: 4th December 2011, 10:41
  5. Implementing standard library sockets [SOLVED]
    By callinyouin in forum Newbie
    Replies: 1
    Last Post: 20th March 2011, 22:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.