Solved QML/Ajax, cross server request (406 error, Not Acceptable)
-
Hello programmers..
i`m developing an application in Qtquick, so i used Qml to design the interface. and then i used PHP as a server side scrip(to connect to database) and i linked them with AJAX. and it is working very well on my loacal computer.
Now if i try to put my PHP script on the life server i get a 406 error(Not acceptable).
here is my AJAX header code:
this.request.setRequestHeader("Content-type", "text/plain"); this.request.setRequestHeader("Accept", "text/plain"); this.request.setRequestHeader("Accept-Charset", "utf-8");
Now here is my htaccess code on the server:
(i was trying to allow the app to access the server)<IfModule mod_security.c> # Turn off mod_security filtering. SMF is a big boy, it does not need its hands held. SecFilterEngine Off # The below probably isn't needed, but better safe than sorry. SecFilterScanPOST Off </IfModule> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type: application/x-www-form-urlencoded; charset=utf-8" Header set Access-Control-Allow-Headers "Access-Control-Request-Method: GET"
I tested these ajax function on the web browser(loading the same info from the remote server through localhost) and it worked very fine and super fast.
So i dont know why is not working in my QT app...
-
OK I`M ANSWERING MY SELF...
It looks like some servers especially HOSTGATOR do not allow request from unknown or suspecious user-agents.
So my qml app is one of those suspicious UA and thats why i was getting that E406.
i tried to play around with javascript, doing things like:
ajax.setRequestheader("User-agent", "myApp");
but it didnt work...
So thats why i moved from javascript to c++ (QnetworkAccessManger).
QNetworkRequest req; req.setUrl(QUrl(request) ); req.setRawHeader( "User-Agent" , "myApp.17.1" );
and it worked very fine..
Thank u..