Nominate our 2022 Qt Champions!

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

  • Example of site API usage:
    I tried to do GET request like POST, explained here:
    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( "" ) );
    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.

  • 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": 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

  • 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?

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

  • Solve it!

    I just need to replace my url string to:

    More about it:

Log in to reply