You might have come across the following (Not Acceptable) error when trying to download files from some websites using Qt. This error message is generated by ModSecurity and it usually means that for some reason the web server does not allow downloading of the file using the method you are trying. In my case it was because of the User-Agent Header set to a value not allowed by the server. So here is how I fixed it:
First of all I am sharing the error code I received using QNetworkAccessManager::get function.
An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.
Here is the HTML code of the error:
<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>
What I did was that I set the User-Agent Header to something else, I actually set it to “Amin” and it worked fine. Here is the piece of code I used for downloading the file:
QString url = “http://amin-ahmadi.com/somefilesomewhere;
QNetworkRequest req = QNetworkRequest(QUrl(url));
QNetworkReply *reply = nam.get(req);
QByteArray data = reply->readAll();
// Do whatever you want with data
Let me know if you face issues using this code.