我正在使用基于 4.8 版的 QtCreator 为使用带有操作系统的 linux 的设备开发应用程序。
我正在尝试在 QT 中下订单我正在使用以下库
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
我有以下代码片段
{
QString msg;
QString url = "myURL";
QNetworkRequest request = QNetworkRequest(QUrl(url));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json; charset=UTF-8"));
QString message = QString("{\"message\" : %1}").arg("\"hello\"");
QByteArray AliveJson = message.toLatin1();
reply = manager->post(request, AliveJson);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
}
void page100::finished(QNetworkReply *r)
{
qDebug()<<"METOD FINISHED CALLED!";
QString msg;
qDebug()<< r;
qDebug()<< "-----------------------------";
qDebug()<< reply;
if (r == reply) {
int status = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (r->error() == QNetworkReply::NoError && status >= 200 && status < 300) {
msg = QString("successfull reply (%1)").arg(status);//200
qDebug()<<reply->readAll();
} else {
msg = QString("failure reply (%1), %2").arg(status).arg(r->errorString());
qDebug()<<msg;
}
reply = NULL;
} else {
msg = QString("unknown reply, url=%1").arg(r->url().toString());
qDebug()<<msg;
}
r->deleteLater();
ui->plainTextEdit->setPlainText(ui->plainTextEdit->toPlainText() + msg);
qDebug()<<msg;
}
我总是收到以下错误
failure reply(0), socket operation timed out
我试图创建一个新的 url 进行通信,但我不断收到同样的错误。
设备已正确连接到互联网。我已经完成了 ping 程序并且设备可以正常通信