Alosyius
Alosyius

Reputation: 9141

QT Get request parsing JSON

I'm trying to make a GET request in order to authenticate a user. Here is my code to do that:

void MainWindow::on_loginButton_clicked()
{
    QString email = "test";
    QString password = "test";

    nam = new QNetworkAccessManager(this);
    QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),
             this, SLOT(serviceRequestFinished(QNetworkReply*)));

    QUrl url("http://url.com/api.php?action=authenticate_user&email=" + email + "&password" + password);
    QNetworkReply* reply = nam->get(QNetworkRequest(url));
}

void MainWindow::serviceRequestFinished(QNetworkReply* reply)
{
    if(reply->error() == QNetworkReply::NoError) {

        QStringList propertyNames;
        QStringList propertyKeys;

        QString strReply = (QString)reply->readAll();

        qDebug() << strReply;

        QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());

        QJsonObject jsonObject = jsonResponse.object();

        QJsonArray jsonArray = jsonObject["status"].toArray();

        qDebug() << jsonObject["status"].toString();

        foreach (const QJsonValue & value, jsonArray)
        {
            QJsonObject obj = value.toObject();
            qDebug() << value.toString();
        }

    } else {
        qDebug() << "ERROR";
    }

    delete reply;
}

But for some reason qDebug() << strReply; just outputs:

""Missing argument"" 

Upvotes: 4

Views: 10660

Answers (1)

Thomas McGuire
Thomas McGuire

Reputation: 5466

The server tells you that your request is missing an argument. Have a detailed look at the request and double-check it.

QUrl url("http://url.com/api.php?action=authenticate_user&email=" + email + "&password" + password);

Seems to me that the URL is wrong, shouldn't it say "&password=" + ... there?

Upvotes: 4

Related Questions