我正在尝试制作GET request
以验证用户身份。这是我的代码:
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;
}
但由于某种原因qDebug() << strReply;
只输出:
""Missing argument""
答案 0 :(得分:4)
服务器告诉您您的请求缺少参数。详细查看请求并仔细检查。
QUrl url("http://url.com/api.php?action=authenticate_user&email=" + email + "&password" + password);
我觉得网址错误,不应该说"&password=" + ...
吗?