仅当从Qt连接时返回HTTP 406错误的网页

仅当从Qt连接时返回HTTP 406错误的网页,qt,mod-security,qtnetwork,Qt,Mod Security,Qtnetwork,我有一个测试页面设置,其中包含以下代码: <?php $foo = $_GET['foo']; if ($foo == "0" || $foo == "1") { echo $foo; } else { echo "Invalid foo"; } 以下是从Wireshark获得的整个HTTP请求和响应 GET /test-qt.php?foo=1 HTTP/1.1 Connection: Keep-Alive Accept-Encoding: gzip, deflate Acc

我有一个测试页面设置,其中包含以下代码:

<?php

$foo = $_GET['foo'];
if ($foo == "0" || $foo == "1") {
  echo $foo;
} else {
  echo "Invalid foo";
}
以下是从Wireshark获得的整个HTTP请求和响应

GET /test-qt.php?foo=1 HTTP/1.1
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Accept-Language: en-CA,*
User-Agent: Mozilla/5.0
Host: mlecturedownload.com

HTTP/1.1 406 Not Acceptable
Date: Sat, 19 Jan 2013 17:14:37 GMT
Server: Apache
Content-Length: 275
Keep-Alive: timeout=5, max=75
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

<head><title>Not Acceptable!</title><script src='/google_analytics_auto.js'></script></head><body><h1>Not Acceptable!</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>
GET/test qt.php?foo=1 HTTP/1.1
连接:保持活力
接受编码:gzip,deflate
接受语言:en-CA*
用户代理:Mozilla/5.0
主持人:mletcuredownload.com
HTTP/1.1406不可接受
日期:2013年1月19日星期六17:14:37 GMT
服务器:Apache
内容长度:275
保持活动状态:超时=5,最大值=75
连接:保持活力
内容类型:text/html;字符集=iso-8859-1
不可接受!不可接受 在此服务器上找不到请求资源的适当表示形式。此错误由Mod_Security生成

看起来服务器上名为mod_security的Apache模块导致了这个问题。有很多方法可以通过.htaccess禁用此功能,但没有一种方法对我有效。但我宁愿修复问题,而不是禁用模块。有人知道发生了什么事吗

编辑:
我发布的站点链接位于HostGator上。我在我的EC2服务器上做了一个测试页面,它工作得很好,可能是因为我没有启用那个安全模块。我仍然需要让它在HostGator服务器上工作。

我遇到了同样的问题-在尝试下载文件时出现“不可接受”错误。我做了一些谷歌搜索和实验,我发现添加:

request.setRawHeader( "User-Agent" , "Mozilla Firefox" );
获取(请求)前更改结果。:)

我猜服务器无法识别QNetworkRequest的用户代理,这导致了406错误消息。 我需要做更多的测试,但我想我应该分享我的突破。
我希望它有帮助……

以下解决方案对我来说是一笔交易:

    request.setRawHeader( "Accept" , "*/*" );

它更像是一个被阻止的用户代理。将用户代理头设置为任何其他项,它应该可以正常工作

request.setHeader(QNetworkRequest::UserAgentHeader, "Whatever you like");

也有同样的问题。通过添加标题来解决此问题。谢谢
request.setHeader(QNetworkRequest::UserAgentHeader, "Whatever you like");