[英]QT request https url, ok in windows ko in linux
我在 QT 中有以下代碼,可以正確獲取 Windows ( 7 x64 ) 中的網頁,但不能在 Linux Debian 9.13 中獲取網頁
void Mycl::getdata()
{
QNetworkAccessManager *networkManager;
networkManager = new QNetworkAccessManager(this);
QString urlStr="https://.......");
QUrl url(urlStr);
QNetworkRequest request;
request.setUrl(url);
connect (networkManager,SIGNAL(finished(QNetworkReply*)),this, SLOT(done(QNetworkReply*)));
networkManager->get(request);
}
void Mycl::done(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError)
{
QString data = QString(reply->readAll ());
在 Debian 中,我在運行時收到以下錯誤:
警告:QSslSocket:需要 OpenSSL >= 1.1.1; OpenSSL 1.1.0l 2019 年 9 月 10 日改為 ((null):0, (null))
警告:QSslSocket::connectToHostEncrypted:TLS 初始化失敗((空):0,(空))
調試:“TLS 初始化失敗”(../Shiva2/mycl.cpp:65,void Mycl::done(QNetworkReply*))
我在操作系統中安裝了以下 package:
ii libssl1.0.2:amd64 1.0.2u-1~deb9u6 amd64 Secure Sockets 層工具包 - 共享庫
ii libssl1.1:amd64 1.1.0l-1~deb9u4 amd64 Secure Sockets 層工具包 - 共享庫
ii libssl-dev:amd64 1.1.0l-1~deb9u4 amd64 Secure Sockets 層工具包 - 開發文件
ii openssl 1.1.0l-1~deb9u4 amd64 Secure Sockets 層工具包 - 加密實用程序
我不知道這個錯誤是否與這個包有關......有什么建議嗎? 謝謝
更新:嘗試將包更新到 debian bullseye ( stable ) 我在依賴項上收到以下錯誤:
dpkg -i libc6_2.31-13+deb11u2_amd64.deb
dpkg: regarding libc6_2.31-13+deb11u2_amd64.deb containing libc6:amd64:
libc6:amd64 breaks locales (<< 2.31)
locales (version 2.24-11+deb9u4) is present and installed.
dpkg: error processing archive libc6_2.31-13+deb11u2_amd64.deb (--install):
installing libc6:amd64 would break locales, and
deconfiguration is not permitted (--auto-deconfigure might help)
Errors were encountered while processing:
libc6_2.31-13+deb11u2_amd64.deb
我也無法升級完整的操作系統,因為它是租用的虛擬服務器。 我應該使用哪個版本的 QT?
它說你必須有 openssl 版本 1.1.1 或更高版本。 但是開箱即用的 Debian 9 只支持 1.1.0。 因此,您必須升級 openssl 或降級 Qt。 在這里,您可以在 debian 9 中找到如何升級 openssl。
當然,您可以更新您的操作系統,但這看起來是最棘手的方法。 :)
這是由於您的操作系統提供的 openssl 版本和 QT 所需的版本。
避免升級/降級操作系統 openssl 版本,嘗試連接到 QNetworkAccessManager 信號:
void QNetworkAccessManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
並在您的插槽中調用reply->ignoreSslErrors()
。
如果這不起作用,請將 QT openssl.so 文件復制到您的 PATH 中的某個位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.