0
Qt如何通過SSL發送簡單的帖子HTTPS?
程序應該使用QNetworkAccessManager通過HTTPS發送帖子。
下面是我的代碼的一個簡單示例。Qt如何發送帖子HTTPS with SSL
QUrlQuery params;
QByteArray dane;
params.addQueryItem("mWyslijpost", ui->lineEdit->text());
dane.append(params.toString());
QUrl url("https://81.2.244.83/Testpostssl/infotest.php");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
QNetworkReply *reply = manager->post(request, dane);
QFile certFile(":/crt/cert.crt");
Q_ASSERT(certFile.open(QIODevice::ReadOnly));
QSslCertificate cert(&certFile, QSsl::Pem);
QSslSocket * sslSocket = new QSslSocket(this);
sslSocket->addCaCertificate(cert);
sslSocket->connectToHostEncrypted(SERVER, 443);
if (!sslSocket->waitForEncrypted())
{
qDebug() << "Info " << sslSocket->errorString();
return false;
}
QSslConfiguration config = sslSocket->sslConfiguration();
config.setProtocol(QSsl::TlsV1_2);
sslSocket->setSslConfiguration(config);
reply->setSslConfiguration(config);
// wait
QEventLoop elCzekaj;
connect(reply, SIGNAL(finished()), &elCzekaj, SLOT(quit()));
elCzekaj.exec();
if(reply->error() == QNetworkReply::NoError)
{
qDebug() << reply->readAll();
}
else
{
qDebug() << "Error...";
qDebug() << reply->errorString();
}
如何從服務器下載證書? 如何配置QSsl?