0

我正在尝试将 QNetworkRequest 与 XP-Dev 一起使用,但我没有运气。

我已经发布了 mu 代码,但省略了某些公司详细信息。

我收到回复错误代码 99,未知网络错误。

我究竟做错了什么?

QNetworkRequest req(QUrl("https://mycomp.xp-dev.com/api/v1/user"));

QJsonObject user;

user.insert("username", "OttoMann");
user.insert("email", "o.mann@springfieldelementary.com");
user.insert("password", "Abdc4312");
user.insert("userRole", "Administrator");

QByteArray jsonstring = QJsonDocument(user).toJson();
QByteArray jsonsize = QByteArray::number(jsonstring.size());

QNetworkAccessManager nam;

req.setRawHeader("Content-Type", "application/json");
//req.setRawHeader("Content-Length", jsonsize);
req.setRawHeader("X-XPDevToken", "(removed obviously)");

QNetworkReply *reply = nam.post(req, jsonstring);

int count = 0;
while (!reply->isFinished())
{
    qApp->processEvents();
    count++;
}

QNetworkReply::NetworkError  err1 = reply->error();

if (err1 == QNetworkReply::NoError)
{
    QByteArray response_data = reply->readAll();

    QJsonDocument json = QJsonDocument::fromJson(response_data);

    int x = 1;
}
else
{
    int error = 1;
}
4

0 回答 0