2012-08-31 78 views
2

有一個Web服務器不支持SSLv2 HELO,因此我必須強制QWebView執行SSLv3 HELO。不幸的是,下面不工作:如何強制QWebView使用SSLv3?

QList ciphers = QSslSocket::supportedCiphers(); 
for (int i = ciphers.count() - 1; i >= 0; i--){ 
    QSslCipher cipher = ciphers.at(i); 
    QSsl::SslProtocol protocol = cipher.protocol(); 
    if (protocol == QSsl::SslV2){ 
     ciphers.removeAt(i); 
    } 
} 
QSslSocket::setDefaultCiphers(ciphers); 

回答

4

通過重寫QNetworkAccessManager的虛擬的createRequest功能,您可以強制其特定的SSL協議:

MyNetworkAccessManager::MyNetworkAccessManager(
       QNetworkAccessManager *oldManager, QObject *parent /*= 0*/) 
    : QNetworkAccessManager(parent) 
{ 
    setCache(oldManager->cache()); 
    setCookieJar(oldManager->cookieJar()); 
    setProxy(oldManager->proxy()); 
    setProxyFactory(oldManager->proxyFactory()); 
} 


QNetworkReply* MyNetworkAccessManager::createRequest(
     QNetworkAccessManager::Operation op, const QNetworkRequest &req, 
     QIODevice *device) 
{ 
    QSslConfiguration sslConfig = req.sslConfiguration(); 
    sslConfig.setProtocol(QSsl::SslV3); 
    req.setSslConfiguration(sslConfig); 
    return QNetworkAccessManager::createRequest(op, req, outgoingData); 
} 


view = new QWebView(this); 
QNetworkAccessManager *oldManager = view->page()->networkAccessManager(); 
MyNetworkAccessManager *newManager = new MyNetworkAccessManager(oldManager, this); 
view->page()->setNetworkAccessManager(newManager);