侧边栏壁纸
博主头像
三味的小站博主等级

世界上没有偶然,有的只是必然的结果。

  • 累计撰写 61 篇文章
  • 累计创建 13 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录
Qt

Qt6 QNetworkRequest ProtocolInvalidOperationError(302)

三味线
2021-11-02 / 0 评论 / 0 点赞 / 20 阅读 / 912 字

在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.

0

评论区