• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Issues trying to use HTTP_POST_STRING Returning -1

Japster

Member
Hi guys! - I'm having a pain of an issue trying to correctly get back info from a http_post_string() in the HTTP ASYNC events (Get scores etc)...

For windows target builds, it works *perfectly* - I get scores, can update player's name, etc, but in HTML5, I just get a "-1" back?- it's failing to get the scores, submit a player's name etc, basically all of the http_post events - they come back with a valid ID, but the result is always -1... ...and it's driving me crazy...

Any advice would be most appreciated!

The relevant code is here, and I just can't understand why it's not working when actually uploaded to the web, or testing on Mongoose or GMS2 dev env / HTML server?

I've tried both HTTPS and HTTP - both work for the Altervista domain / URL, for the Windows build, but not the HTML5 one?


objHighscoresPersistent - alarm 2 event that tries to get the scores:-
GML:
if (text2 == "")
{
    get_highscores = scr_get_scores(Unique_Player_ID, 10);
    text1 = "Please check your internet connection...";
    alarm[2] = room_speed * 5;
}
The scr_get_scores script:-

GML:
/// @description scr_get_scores(player_id,no_lines)
/// @param name            ID of the player
/// @param no_lines        the number of scores you want to display (generally 10 is fine)
//
// Script:      Get the highscore list from the database in Altervista
// Date:        2020-01-18
// Copyright:   Appsurd

var args = "id="+string(argument0)+"&no_lines="+string(argument1)+"&secret_key="+SecretKey;
return http_post_string(url + "/display.php", args);
objHighscoresPersistent HTTP ASYNC event:-

GML:
if (ds_map_find_value(async_load, "id") == get_highscores)
{
//    Wallet_No = "RETURNED HIGH";

    if (ds_map_find_value(async_load, "status") == 0)   //   (THIS always returns -1 for HTML?!)
    {       
        text2 = string(ds_map_find_value(async_load, "result"));   

//        Wallet_No = text2;

        show_debug_message(text2);
        if (text2 == "IOException" or text2 == "")
        {
            text1 = "Please check your internet connection...";
            text2 = "";
        }
        else
        {
            text1 = "Ready";
        
//            Wallet_No = text2;
        
            Got_Scores = true;
        
            alarm[2] = -1;
            alarm[10] = 1;
        }
    }
    else
    {
//        Wallet_No = "!! "+string(ds_map_find_value(async_load, "status"));
    }
    exit;
}

I honestly cannot understand why it's returning -1 in the live environment, or itch.io, etc - on the HTML5 build! :(

It wouldn't be a browser security setting would it? - I'm clutching at straws here! :(

Cheers all!
 

FrostyCat

Redemption Seeker
I honestly cannot understand why people keep missing this line, which every HTTP function entry in the Manual has:
NOTE: You should be aware that due to XSS protection in browsers, requests to and attempts to load resources from across domains are blocked and may appear to return blank results. Please see the part on Cross Domain Issues for further details.
Since you appear to be using raw PHP, here is an example of implementing CORS.
 

Japster

Member
As always, @FrostyCat - legend! - I'm not sure why I missed it too! - I checked the manual for the HTTP_POST_STRING command - not sure why I missed it if so.... :(

But again, thanks as always! - @Appsurd also came back to me with the fix, so thank you both! :D
 
Top