Is this the right way to set the SSL protocol with QWebPage?

前端 未结 2 515
难免孤独
难免孤独 2021-01-07 01:10

I\'ve been working with SSL in Qt, where I need to set a specific protocol (instead of the default \"secure protocols\"). It looks like this works:

QSslConfi         


        
2条回答
  •  萌比男神i
    2021-01-07 01:39

    The way I've found to do this is to extend QNetworkAccessManager and set the protocol in createRequest:

    class NetworkAccessManager : public QNetworkAccessManager
    {
        Q_OBJECT
    public:
        explicit NetworkAccessManager(QObject *parent = 0);
    
    protected:
        virtual QNetworkReply * createRequest(Operation operation, const QNetworkRequest & request, QIODevice * outgoingData = 0) {
            // I have no idea why request is const, but I need to change it
            QNetworkRequest notConstRequest = request;
            QSslConfiguration conf = notConstRequest.sslConfiguration();
            conf.setProtocol(QSsl::TlsV1_0);
            notConstRequest.setSslConfiguration(conf);
            return QNetworkAccessManager::createRequest(operation, notConstRequest, outgoingData);
        }
    };
    

    Then I can set it in my QWebpage using setNetworkAccessManager.

提交回复
热议问题