URLRequest post request HTML5 problem


#1

I have a simple POST request, which is working as expected on all platforms except HTML5.
In HTML5, my game sends GET request somehow, any idea why could it happen?

Here is my code:

_req = new URLRequest(url);
_req.data = vars;
_req.method = URLRequestMethod.POST;
_onReq = onReq;
_loader.dataFormat = URLLoaderDataFormat.TEXT;
_loader.load(_req);

#2

I just tried this code in a sample project:

package;


import openfl.display.Sprite;
import openfl.net.*;


class Main extends Sprite {
	
	
	public function new () {
		
		super ();
		
		var vars = new URLVariables ();
		vars.hello = 100;
		
		var _req = new URLRequest("./assets/foo");
		_req.data = vars;
		_req.method = URLRequestMethod.POST;
		//_onReq = onReq;
		var _loader = new URLLoader ();
		_loader.dataFormat = URLLoaderDataFormat.TEXT;
		_loader.load(_req);
		
	}
	
	
}

Opening the HTTP debugger, and checking the Network tab (after a refresh), showed the following:

Request URL:http://127.0.0.1:3000/assets/foo
Request Method:POST
Status Code:405 Method Not Allowed
Remote Address:127.0.0.1:3000
Referrer Policy:no-referrer-when-downgrade

So the address I requested was bad, but looks like it is sending the request as POST properly


#3

Ok, I’ll check with simple project, but my server reporting GET requests from HTML5… :frowning:
Thank you!


#4

Ok, I’ve checked in browser’s dev tools and I get a different results.
Here is request from Flash version:
flash_post

And here is HTML5:
html5_get

UPDATE: Problem occurs when you send request to actual url.
In your example, “./assets/foo” works fine for me too, I see POST request, but changing it to real url makes it OPTIONS. :hushed:


#5

Ah, looks like its part of CORS:


#6

Yeah, it helped!
Thanks a lot! :slight_smile: