Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML/Ajax, cross server request (406 error, Not Acceptable)
Forum Updated to NodeBB v4.3 + New Features

QML/Ajax, cross server request (406 error, Not Acceptable)

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 591 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • chawilaC Offline
    chawilaC Offline
    chawila
    wrote on last edited by
    #1

    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...

    1 Reply Last reply
    0
    • chawilaC Offline
      chawilaC Offline
      chawila
      wrote on last edited by
      #2

      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..

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved