Help with "POST" ing data to server

Hi, I’m new to PlayCanvas (and to some extent web-dev in general) coming from the Unity/C# world.

My team is prototyping a simple game and I’m currently trying to setup a way to GET and POST data from/to a server.

I found the JSON tutorial template which has been very helpful. ( and I’ve gotten the GET function to work well, and parse the JSON data.

However something is happening when I’m trying to POST data, I’m getting a 404 error - when I’m not getting it in the Swagger environment the backend developer setup (there, it’s either 201 or 400 depending on if the data is valid or not). He isn’t sure why we’re getting 404 when trying to POST through PlayCanvas and I wonder if there might be something with my code.

I’ve attached pictures for reference and highlighted the functions I’m concerned about. If anyone has any insight it would be greatly appreciated. Have tried to debug it, and I’m sure it’s something stupid, thought I’d give it a shot here :slight_smile:

Are you calls getting blocked because they are going to http from https page?

You can try running the PlayCanvas launch page as http (just change the URL).

1 Like

In addition to what Dave said, you also need to make sure your server is accepting CORS requests.

1 Like

Thanks - we thought it was https-> http issue (we’ll be doing an https in the future but didn’t have it for testing). But we were able to get around that by just loading “unsafe scripts” on the browser.

I think the actual issue was what Mike has mentioned - the server was reading POST calls as OPTIONS calls (because of CORS?) which weren’t supported, thus the 404. So the backend engineer added support to read OPTIONS calls and parse them properly.

Yeah non-form POST requests send a “pre-flight” OPTIONS request to see if it will be accepted.