qt 发送Https请求

欢迎

代码块

代码块,例如:

#include 
#include 
#include "QtNetwork/QNetworkRequest"
#include "QtNetwork/QNetworkReply"
#include "QtNetwork/QHttpPart"
#include 
#include 
#include 
#include 
#include 
#include 
QNetworkReply *NetController::post(QNetworkRequest request,QUrl url, QByteArray &bytes) {
    //QNetworkRequest request;
    request.setUrl(url);
    //QUrl test_url = QUrl("https://127.0.0.1:3000");
    //request.setUrl(test_url);
    QDir temDir3(QString(g_license_dir.c_str()));
    QString abs_license_path = temDir3.absolutePath();
    QFile license_file(abs_license_path);
    //QFile license_file("E:/server/keys/client.pfx");
    Q_ASSERT(license_file.open(QIODevice::ReadOnly));

    QSslCertificate certificate;
    QSslKey key;
    QList importedCerts;
    std::string passphrase = "";//123456
    bool imported = QSslCertificate::importPkcs12(&license_file, &key, &certificate, &importedCerts, QByteArray::fromStdString(passphrase));
    loge("Imported: %d \n",imported);
    license_file.close();
    QSslConfiguration config = request.sslConfiguration();
    config.setCaCertificates(importedCerts);
    config.setLocalCertificate(certificate);
    config.setPrivateKey(key);
    config.setProtocol(QSsl::AnyProtocol);
    config.setPeerVerifyMode(QSslSocket::VerifyNone);
    request.setSslConfiguration(config);

    std::string sss =  url.toDisplayString().toStdString();//debug
    QNetworkReply *reply = m_pManager->post(request, bytes);

    return reply;
}

依赖的库

  1. QTNetWork。
  2. libeay32.dll ssleay32.dll
  3. 存在以下问题
    1. QT5.5以上开始支持ec加密
    2. QT5.4以上开始支持pfx/p12文件读取

你可能感兴趣的:(C++,QT)