我正在尝试将QNetworkRequest与XP-Dev一起使用,但是我没有运气。
我已经发布了亩代码,但是省略了某些公司详细信息。
我得到的回复错误代码为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;
}