Empfangen von QNetworkReply :: Protocolfailure, um Anfrage zu erhalten
Posted: 06 Feb 2025, 03:18
Ich entschuldige mich für den langwierigen Beitrag. Ich versuche, ein Remote -Programm zu erstellen, das mit einem Hauptprogramm, das auf SBC ausgeführt wird, kommuniziert. Die Fernbedienung muss auf einem Browser ausgeführt werden. Die Remote verfügt Anwendung kann ich die Daten ordnungsgemäß aus der Hauptanwendung empfangen. Wenn ich jedoch die Remote -Anwendung mit WebAssembly zusammenstelle, erhalte ich QNetworkReply :: ProtoColfailure jedes Mal, wenn ich eine Antwort aus meiner Haupt -App erhalte.
Überwachung der HTTP Richtig. Der Client hatte QTExtedit -Widget, um Debug -Informationen auszugeben.
mainWindow.h
MainWindow.cpp
mainwindow.h:
MainWindow.cpp
Weiß jemand, warum dies geschieht und wie dies auflöst?
Überwachung der HTTP Richtig. Der Client hatte QTExtedit -Widget, um Debug -Informationen auszugeben.
Code: Select all
#include "mainwindow.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Code: Select all
ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
int const NETWORK_PORT_SERVER {12345};
int const NETWORK_PORT_CLIENT {23456};
QTcpServer *tcpServer;
QHttpServer hServer;
};
#endif // MAINWINDOW_H
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
tcpServer = new QTcpServer(this);
tcpServer->listen(QHostAddress("192.168.86.48"), NETWORK_PORT_SERVER);
hServer.bind(tcpServer);
hServer.route("/", QHttpServerRequest::Method::Options, []()
{
QHttpServerResponse res(QHttpServerResponse::StatusCode::NoContent);
res.addHeader("Allow", "*");
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Language", "*");
res.addHeader("Access-Control-Allow-Encoding", "*");
res.addHeader("Access-Control-Allow-Method", "*");
res.addHeader("Access-Control-Allow-Headers", "*");
return res;
});
hServer.route("/", QHttpServerRequest::Method::Get, []()
{
QString testAnswer = "TEST REPLY";
QHttpServerResponse res(testAnswer, QHttpServerResponse::StatusCode::Ok);
return res;
});
}
MainWindow::~MainWindow()
{
delete ui;
}
< /code>
Mein Test Client:
[b] main.cpp:[/b]
#include "mainwindow.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Code: Select all
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
int const NETWORK_PORT_SERVER {12345};
int const NETWORK_PORT_CLIENT {23456};
QNetworkAccessManager * manager;
QNetworkRequest req;
private slots:
void serverDataReceived(QNetworkReply *);
};
#endif // MAINWINDOW_H
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->debugInfo->append("Program Started");
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serverDataReceived(QNetworkReply*)));
QUrl contAdress(QString("http://192.168.0.84:%1").arg(NETWORK_PORT_SERVER));
req.setUrl(contAdress);
manager->get(req, "Test");
}
void MainWindow::serverDataReceived(QNetworkReply * rep)
{
ui->debugInfo->append("Reply Received");
QVariant status = rep->attribute(QNetworkRequest::HttpStatusCodeAttribute);
ui->debugInfo->append(status.toString());
ui->debugInfo->append(QString("Network Error: %1").arg(static_cast(rep->error())));
ui->debugInfo->append(rep->readAll());
}
MainWindow::~MainWindow()
{
delete ui;
}