在Qt6.2.1中使用HTTP GET请求时,出现了错误:QNetworkReply::ProtocolInvalidOperationError,但是用postman调用同一接口就是正常的,用Wireshark查看2次请求的header发现,Qt6使用了HTTP/2:
正常的:
错误的:
需要禁用HTTP/2才能正常请求:
mRequest.setAttribute(QNetworkRequest::Http2AllowedAttribute, false);
该属性描述:
Requests only, type: QMetaType::Bool (default: true) Indicates whether the QNetworkAccessManager code is allowed to use HTTP/2 with this request. This applies to SSL requests or 'cleartext' HTTP/2.
评论区