如何忽略所有SSL错误?

时间:2017-05-09 07:01:48

标签: qt ssl websocket

试图忽略:

The host name did not match any of the valid hosts for this certificate

QWebSocket::open()

之前使用此代码
QObject::connect(&sock,
                 &QWebSocket::sslErrors,
                 &sock,
                 static_cast<void(QWebSocket::*)(const QList<QSslError>&)>(&QWebSocket::ignoreSslErrors),
                 Qt::DirectConnection);

但错误仍在发生。怎么了?

1 个答案:

答案 0 :(得分:0)

需要添加正常的回调,然后处理错误:

    QObject::connect(&sock,
                     &QWebSocket::sslErrors,
                     this,
                     &MyClass::sslError,
                     Qt::DirectConnection);

...

void MyClass::sslError(const QList<QSslError>& errors)
{
    // Here QWebSocket::ignoreSslErrors() can be called.
}