gpt4 book ai didi

c++ - Qt QNetworkReply 连接关闭

转载 作者:太空宇宙 更新时间:2023-11-04 11:58:40 29 4
gpt4 key购买 nike

我尝试在 C++ 中对 url https://... 执行 post 方法,但我收到连接关闭错误。

如果我使用另一个 url,比如 https://www.google.gr,我发现我的代码可以工作。

如果我删除端口 8181,我会收到错误消息:server replied:not found

我的代码是

static const char *REQUEST_URL="https://...";
static const char *USER = "....";
static const char *PASSWORD = "....";

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
finishedexecuted=0;
QByteArray postData;
postData.append("username=...");
postData.append("password= ...");
m_network = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl url=QUrl(REQUEST_URL);
request.setUrl(url);
QSslConfiguration config = request.sslConfiguration();
QList<QSslCertificate> certs =
QSslCertificate::fromPath("pistopoiitiko.crt");
config.setCaCertificates(certs);
request.setSslConfiguration(config);
QNetworkReply *reply = m_network->post(request,postData);

downloadTime.start();
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
SLOT(slotSetProgress(qint64,qint64)));
QObject::connect(m_network, SIGNAL(finished(QNetworkReply *)),
SLOT(slotRequestFinished(QNetworkReply *)));

connect(m_network,
SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)),
this,
SLOT(sslError(QNetworkReply*, const QList<QSslError> &)));
}

void MainWindow::sslError(QNetworkReply* reply,
const QList<QSslError> &errors )
{...}

void MainWindow::slotRequestFinished(QNetworkReply *reply)
{
...
if (reply->error() > 0) {
m_label->setText("Error number = " + reply->errorString());
}
...
}

void MainWindow::slotSetProgress(qint64 received, qint64 total)
{...}

有什么想法吗?

最佳答案

我用这段代码解决了这个问题

QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setProtocol(QSsl::SslV3);

然后我收到了我用 ignoresslerrors() 传递的 ssl 错误

关于c++ - Qt QNetworkReply 连接关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15063824/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com