Httprequest - Get issue with firefox

Monkey Targets Forums/HTML5/Httprequest - Get issue with firefox

Bob(Posted 2014) [#1]
I've modified the get section of the bananas/httprequest example so that the URL points to a .php script that returns a list of current high scores. When I run the example in Chrome or IE it works fine and returns the list as expected. When it is run in Firefox, I get a blank response.

Pasting the URL of the script directly into a browser address bar also returns the high score list in both Chrome and IE. However, when I try it in Firefox, I noticed it changes the pasted text slightly:

from: http://www.DOMAINNAME.com/highscore.php?function=read
to: http://www.DOMAINNAME.com/highscore.php/?function=read

Removing the added / after .php causes the high score list to be displayed as it does in the other browsers.

Has anyone else had issues with Firefox and .php scripts? Does Firefox add always add the extra / to the request thus causing it to point to an invalid address?


nikoniko(Posted 2014) [#2]
Bob wrote:
However, when I try it in Firefox, I noticed it changes the pasted text slightly:

from: http://www.DOMAINNAME.com/highscore.php?function=read
to: http://www.DOMAINNAME.com/highscore.php/?function=read


Webserver does usually that. Test via Dev Tools (F12) uri to server and server's answer(s).


Bob(Posted 2014) [#3]
This is the error being shown when I use DEV Tools:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at URL. This can be fixed by moving the resource to the same domain or enabling CORS.

The PHP file it is trying to access uses this header: header("Access-Control-Allow-Origin: *");

Is there somewhere else Cross Origin needs to be enabled?


nikoniko(Posted 2014) [#4]
Try load game from the same domain where php scripts running to exclude cors issue.


Bob(Posted 2014) [#5]
I get the same Cross-Origin Request Blocked error even with everything on the same domain.
Does CORS need to be set in MonkeyGame.html or main.js also, or is setting it in the .php script the only place needed?


nikoniko(Posted 2014) [#6]
Bob wrote:
or is setting it in the .php script the only place needed?


On the server side (php script) only.

Bob wrote:
Does CORS need to be set in MonkeyGame.html or main.js also


CORS is set to domain.

Note: www.domain.com and domain.com are the different domains. Check your webserver doesn't make redirect from www.domain to domain or vise versa.
If your game requests page/script on www.domain but get answer from domain you got CORS violation.


nikoniko(Posted 2014) [#7]
Also browsers can block crossdomain requests from loca file system or localhost domain.

See some way to fix:
http://stackoverflow.com/questions/10883211/deadly-cors-when-http-localhost-is-the-origin


Bob(Posted 2014) [#8]
I've tried changing the URL of the .php file to include www and also without www. The Firefox dev tools error updates to reflect the URL change, but gives the same error.

I also tried changing the name of the .php file being pointed to in the code to one that doesn't exist and I still get Same Origin Policy error. Could the error I'm getting be caused by the file not being found due to the extra / in the URL?

The FireFox Dev Tools console says it is unable to read the resource at URL/highscore.php/?function=read


TeaBoy(Posted 2014) [#9]
Hi Bob,

Not sure if your still having probs, but I have been working on a little prompt for my web server using php and monkey and it seems to
work ok for me at the moment.

The example works on the local server and on my host too.

Not the best example I know but I hope it could help you out.

This works on Firefox.

httprequests:
Method SendRequest()
    getRequest.Open("GET", "http://127.0.0.1/tomo/monkeyprompt.php?cmd="+Self.text, Self)
    getRequest.Send
End Method


php script to pass command to:
  if(!empty($_GET))
  {
    $getCmd = $_GET['cmd'];
	
    $cmdArray = array("ls", "help");
    
    if(!array_keys($cmdArray, $getCmd))
    {
      echo "Command does not exist, Please type 'help' for a list of supported commands.";
	  exit(1);
    }
	
	//$output = shell_exec($getCmd);
	//echo $output;
    
	switch($getCmd)
    {
      case "ls":
	    ls();
	  break;
	  
	  case "help":
	    help($cmdArray);
	  break;
    }
   }
   
  function ls()
  {
    $contents = '';
	
    if ($hndDir = opendir('.')) 
	{
      while (($entry = readdir($hndDir)) !== false) 
	  {
	    if(is_dir($entry))
		{
		  printf("%s - [DIR]\n", $entry);
		}
		else
		{
         printf("%s - [FILE]\n", $entry);
		}
      }
    }
    
	closedir($hndDir);
  }
  
  function help($cmdArray)
  {
    foreach($cmdArray as $cmd)
    {
      printf("%s\n", $cmd);
	}
  }
?>



nikoniko(Posted 2014) [#10]
Bob wrote:
The FireFox Dev Tools console says it is unable to read the resource at URL/highscore.php/?function=read


What IE/Chrome consoles says?


Bob(Posted 2014) [#11]
@nikoniko
Chrome - Shows no errors in the console and the top 10 scores load correctly

IE - Shows "XMLHttpRequest for http://URL/highscore.php?function=read required Cross Origin Resource Sharing (CORS)." The top 10 scores still load correctly despite the error. Notice there is no additional "/" after highscore.php.

@TeaBoy
Have you happened to try this with the Firefox Dev Console open? If so did you see any calls to your monkeyprompt.php with an extra / after the file name?


nikoniko(Posted 2014) [#12]
Read this
https://support.mozilla.org/en-US/questions/951951


Bob(Posted 2014) [#13]
I thought for sure that would fix it, but I get the same result. The Dev Console still shows the extra slash in the URL.


TeaBoy(Posted 2014) [#14]
Hi Bob, looking at the dev console, see no / using Firefox 29.0.1

Everything seems to run ok.


nikoniko(Posted 2014) [#15]
Bob wrote:
I thought for sure that would fix it, but I get the same result. The Dev Console still shows the extra slash in the URL.


Create new empty profile (firefox.exe -p to get access profile manager) and try from here.


skid(Posted 2014) [#16]
The first issue (I think as monkey docs aren't explicit) is that you are not url encoding Self.text ( the symbol = is reserved ).


Bob(Posted 2014) [#17]
@skid
I'm not sure I follow. How would that be implemented if my HttpRequest looks like this:

get_req=New HttpRequest( "GET","http://URL\highscore.php?function=read",Self )


skid(Posted 2014) [#18]
I'm not positive but that example has two problems:

1. the backslash will produce issues on some platforms
2. the = may need to be replaced with escaped version %3d

I'm going to hunt down the relevant RFC regarding equals cos I'm not sure I'm correct.

[edit]

OK I'm none the wiser :( http://tools.ietf.org/html/rfc3986


golomp(Posted 2014) [#19]
Hi,

Maybe if domains are differents, it's not in agrement with W3C rules ?

Regards,
Golomp