[英]No reply data with QNetworkAccessManager when running on another machine
I have a simple program that should retrieve the HTML from a website URL.我有一个简单的程序,应该从网站 URL 检索 HTML。
main.cpp主.cpp
#include "Downloader.h"
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto dl = new Downloader(&a);
QString url = "https://www.dognow.at/ergebnisse/?page=1";
dl->fetch(url);
return a.exec();
}
Downloader.h下载器.h
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QNetworkReply>
#include <QObject>
class Downloader : public QObject
{
Q_OBJECT
public:
explicit Downloader(QObject* parent = nullptr);
void fetch(QString &url);
private:
QNetworkAccessManager* m_manager;
private slots:
void replyFinished(QNetworkReply* rep);
};
#endif // DOWNLOADER_H
Downloader.cpp下载器.cpp
#include "Downloader.h"
#include <QDebug>
Downloader::Downloader(QObject* parent): QObject(parent),
m_manager(new QNetworkAccessManager(parent))
{}
void Downloader::fetch(QString& url)
{
qDebug() << "fetch " << url;
connect(m_manager, &QNetworkAccessManager::finished, this, &Downloader::replyFinished);
m_manager->get(QNetworkRequest(QUrl(url)));
}
void Downloader::replyFinished(QNetworkReply* rep)
{
QByteArray data=rep->readAll();
QString str(data);
qDebug() << "data len: " << str.length();
rep->close();
}
When I run the program on my local PC it works fine.当我在本地 PC 上运行该程序时,它工作正常。 When I run it on another machine the reply data is empty.当我在另一台机器上运行它时,回复数据是空的。 On both systems I use Linux (x86_64) and Qt 5.15.0.在这两个系统上,我都使用 Linux (x86_64) 和 Qt 5.15.0。
I hope someone can give me a hint where I should have a look at.我希望有人能给我一个提示,我应该去哪里看看。
UPDATE: 2022-04-04 - 16:22: when I run a simple curl command on the failing machine it works fine.更新:2022-04-04 - 16:22:当我在故障机器上运行一个简单的 curl 命令时,它工作正常。
Ok, I found the problem.好的,我发现了问题。 On the failing machin I have an older ubuntu (16.04 LTS) running with an incompatible openssl version.在出现故障的机器上,我有一个旧的 ubuntu (16.04 LTS) 运行着一个不兼容的 openssl 版本。 I found it out because I copied my own Qt libs build (debug) to the other machine and I got SSL error (incompatbile version).我发现它是因为我将自己的 Qt 库构建(调试)复制到另一台机器上,但出现 SSL 错误(不兼容版本)。 I installed a newer openssl version and know it works.我安装了更新的 openssl 版本并且知道它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.