QT中支持https连接

    处理说明:先进行相应的设置,注意与http不同的是,要设置相应的端口和conf.setProtocol(QSsl::SslV3);

    /并且要进行出错处理(在网页上连接时,会提示不可靠连接或不受信任的连接, 此时选择忽略并继续)


   /以下为主干的处理  begin

   QNetworkAccessManager *networkMng; //连接

    QNetworkReply *reply; //网络相应的回应


connect(networkMng,SIGNAL(sslErrors(QNetworkReply * , const QList & )),
this,SLOT(slotSSLErrorDeal(QNetworkReply * , const QList & )));


QUrl urlTemp(m_serverURL);
urlTemp.setPort(iHttpsPort); 此处设置该端口号


QNetworkRequest requestTemp(urlTemp);
requestTemp.setHeader(QNetworkRequest::ContentTypeHeader, "application/zip");
requestTemp.setRawHeader("filename", logFile.toUtf8() );

QSslConfiguration conf = requestTemp.sslConfiguration();
conf.setProtocol(QSsl::SslV3);
requestTemp.setSslConfiguration(conf);


reply = mp_networkMng->post(requestTemp, l_content);


       connect(reply,SIGNAL(finished()),
        this,SLOT(slotUploadLogFinished()));

    //等待上传
    int waitCount = 1;
    while(waitCount)
    {
        Sleep(10000);
        waitCount--;
    }

   /end

 ///以下为出错的处理. begin

void CMyclass::slotSSLErrorDeal(QNetworkReply * reply, const QList & errors)
{

QList::const_iterator conit = errors.begin();
while(conit != errors.end())
{
QString sTemp =  (*conit).errorString();
writeTestDebugLog(sTemp);  ///打印错误日志
qDebug()<< (*conit).errorString();
++conit;
}
reply->ignoreSslErrors();

return;
}

 ///end

你可能感兴趣的:(技术)