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

gsi*_*011 6 qt mod-security qtnetwork

我在http://mlecturedownload.com/test-qt.php上设置了测试页面,其中包含以下代码:

<?php

$foo = $_GET['foo'];
if ($foo == "0" || $foo == "1") {
  echo $foo;
} else {
  echo "Invalid foo";
}
Run Code Online (Sandbox Code Playgroud)

在Web浏览器中转到此页面并修改foo的值可以正常工作,并且使用curl也可以正常工作.但是当我从Qt发送请求时,我得到一个HTTP 406错误代码,这意味着"不可接受".以下是我提出请求的方式:

void MainWindow::on_send_clicked()
{
    QString url = "http://mlecturedownload.com/test-qt.php?foo=1";

    QNetworkRequest request;
    request.setUrl(QUrl(url));
    nam->get(request); // nam is a QNetworkAccessManager
}
Run Code Online (Sandbox Code Playgroud)

这是从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>
Run Code Online (Sandbox Code Playgroud)

它看起来像服务器上名为mod_security的Apache模块导致了问题.有一些方法可以通过.htaccess禁用它,但是没有一个方法可以帮助我.但我宁愿修复问题而不是禁用模块.有谁知道发生了什么?

编辑:我发布的网站链接托管在HostGator上.我在我的EC2服务器上做了一个测试页面,它工作正常,可能是因为我没有启用该安全模块.我仍然需要在HostGator服务器上运行它.

dv8*_*dv8 9

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

request.setRawHeader( "User-Agent" , "Mozilla Firefox" );
Run Code Online (Sandbox Code Playgroud)

在get(请求)之前更改结果.:)

我猜QNetworkRequest的用户代理无法被服务器识别,并且导致406错误消息.我需要做更多的测试,但我认为我应该分享我的突破.我希望它有所帮助......