Qt QNetworkReply 连接关闭

编程入门 行业动态 更新时间:2024-10-25 19:27:22
本文介绍了Qt QNetworkReply 连接关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试在 c++ 中将 post 方法执行到 url ...,但我收到连接关闭错误.

I try to execute post method in c++ to a url ..., but I receive connection closed error.

如果我使用像 www.google.gr 这样的其他网址,我发现我的代码可以正常工作.

I see that my code works if I use another url like www.google.gr.

如果我删除端口 8181 我会收到错误:服务器已回复:未找到.

If I remove the port 8181 I get error: server replied:not found.

我的代码是

static const char *REQUEST_URL="..."; 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) {...}

有什么想法吗?

推荐答案

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

i achieved to overcome this problem with this code

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

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

then i received ssl errors that i passed with ignoresslerrors()

更多推荐

Qt QNetworkReply 连接关闭

本文发布于:2023-10-13 00:24:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Qt   QNetworkReply

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!