I have a test page setup at http://mlecturedownload.com/test-qt.php that has the following code:
<?php
$foo = $_GET['foo'];
if ($foo == "0" || $foo == "1") {
echo $foo;
} else {
echo "Invalid foo";
}
Going to this page in a web browser and modifying the value of foo works fine, and using curl works fine as well. But when I send a request from Qt I get an HTTP 406 error code, which means "Not acceptable". Here is how I make the request:
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
}
Here's the entire HTTP request and response obtained from Wireshark
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>
It looks like an Apache module on the server called mod_security is causing the problem. There are ways to disable this through the .htaccess, but none have them have worked for me. But I'd rather fix the problem instead of disabling the module. Does anyone know what's going on?
Edit: The link to the site I posted is hosted on HostGator. I made a test page on my EC2 server and it worked fine, probably because I don't have that security module enabled. I still need to get it working on the HostGator server.