本文介绍了Qt QNetworkReply连接关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试在c ++中执行post方法到url https:// ... ,但我收到连接关闭错误。 我看到如果我使用 https://www.google.gr 的另一个网址,我的代码可以正常工作。 如果我删除端口 8181 我得到错误:服务器回复:找不到 / p> 我的代码是 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错误 I try to execute post method in c++ to a url https://..., but I receive connection closed error.I see that my code works if I use another url like https://www.google.gr.If I remove the port 8181 I get error: server replied:not found.My code isstatic 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){...}Any ideas? 解决方案 i achieved to overcome this problem with this codeQSslConfiguration config = QSslConfiguration::defaultConfiguration();config.setProtocol(QSsl::SslV3);then i received ssl errors that i passed with ignoresslerrors() 这篇关于Qt QNetworkReply连接关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-08 16:27