Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Can't understand howto send HTTP GET request with authentication

[SOLVED] Can't understand howto send HTTP GET request with authentication

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 8.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RazrFalcon
    wrote on 3 Dec 2011, 17:03 last edited by
    #1

    Example of site API usage: http://myanimelist.net/modules.php?go=api#animemangasearch
    I tried to do GET request like POST, explained here: http://developer.qt.nokia.com/forums/viewthread/10771/#60273
    but I didn't understand how to pass authentication.

    Here is code example (based on ZapB's example, i rewrite only login function):
    @void network::login( const QString& userName, const QString& password )
    {
    qDebug() << "Attempting to login with Username =" << userName << "and password =" << password;
    m_userName = userName;

    QNetworkRequest request;
    request.setUrl( QUrl( "http://myanimelist.net/api/anime/search.xml?q=bleach" ) );
    
    request.setRawHeader( "User-Agent", "ZapB's QtDevNet Client 0.1" );
    request.setHeader( QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded" );
    
    QNetworkReply* reply = m_nam->get(request);
    connect( reply, SIGNAL( finished() ),
             SLOT( _q_onLoginRequestFinished() ) );
    connect( reply, SIGNAL( metaDataChanged() ),
             SLOT( _q_onLoginMetaDataChanged() ) );
    connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
             SLOT( _q_onLoginRequestError( QNetworkReply::NetworkError ) ) );
    

    }@
    And I get such errors:
    @Attempting to login with Username = "my_nick" and password = "my_pass"
    void network::_q_onLoginMetaDataChanged()
    "Loging request failed: Unauthorized."
    void network::_q_onLoginRequestError(QNetworkReply::NetworkError)
    Error when logging in: "Host requires authentication"
    void network::_q_onLoginRequestFinished() @
    Thanks for advise.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mabrouk
      wrote on 3 Dec 2011, 19:55 last edited by
      #2

      as mentioned you need to be authenticated first to able to use this service
      you should first authorize your app to be able to use the services

      if all you want is to learn you can try to send request to "google weather api":http://www.google.com/ig/api?weather=london for example and you'll find it's working
      if you wanna use the services of this site, check first what's needed to authorize your app so you can use the services

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RazrFalcon
        wrote on 3 Dec 2011, 21:22 last edited by
        #3

        Emmm... I'm registered on this site, but I didn't understand what you mean with "authorize your app".
        You mean masking my app as browser?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mabrouk
          wrote on 3 Dec 2011, 22:15 last edited by
          #4

          it depends on how the services are made, but it's something like that

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RazrFalcon
            wrote on 4 Dec 2011, 00:43 last edited by
            #5

            Solve it!

            I just need to replace my url string to:
            @request.setUrl(QUrl("http://login:password@myanimelist.net/api/anime/search.xml?q=bleach");@

            More about it: http://doc.qt.nokia.com/4.7-snapshot/qurl.html#setAuthority

            1 Reply Last reply
            0

            1/5

            3 Dec 2011, 17:03

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved