如何获取使用QNetworkRequest发送的请求的http头的原始字节数据

3
我正在使用QNetworkRequest来执行https请求。我想要调试并查看该类构建的http头的所有内容,然后再将其发送到https服务器之前。
到目前为止,我的做法是:
QString header_list;
QList<QByteArray> headerList = request->rawHeaderList();
foreach(QByteArray head, headerList)
   header_list += head + ": " + request->rawHeader(head) + "\n";

这会生成一个字符串,其中包含我使用setRawHeader显式设置的所有标头部分,但它不显示默认情况下或由类本身添加的值,而无需我的干预。
通常,我会使用tcpdump查看应用程序尝试发送到服务器的内容,但它使用SSL,所以我不能这样做。
我真的很想看到实际发送的“真正”标头,但由于某种原因,它被很好地隐藏在类内部。
是否有任何简单的方法来检索它,以便我可以查看应用程序使用的http标头?
1个回答

3

HTTP头部是在Qt网络模块中深入设置的。您无法获取它们。 默认的头部如下:

Content-Length: 42 // if there is outgoing data
Proxy-Connection: Keep-Alive // if there is http proxy
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,en,* // depend on system locale
User-Agent: Mozilla/5.0
Host: www.google.com
Content-Type: application/x-www-form-urlencoded // if there is outgoing data, depend on data type

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接