GameMaker Post a String to Online Server?

Gamerev147

Member
I'm using an online server called "x10hosting.com/". I'm able to make a text file on the server and get data from it in GMS2.

However, I would like to upload data to this text file on my server using GMS2. Is there anyway this can be done?
Any help is appreciated.
 

chamaeleon

Member
I'm using an online server called "x10hosting.com/". I'm able to make a text file on the server and get data from it in GMS2.

However, I would like to upload data to this text file on my server using GMS2. Is there anyway this can be done?
Any help is appreciated.
Have you implemented server-side part in PHP or whatever else they support that is able to accept a post request? If not, perhaps start there, then just use http_post_string() with the url you have implemented for this purpose together with the data you wish to upload? Needless to say, how to implement accepting a post request in PHP is covered in a multitude of non-GMS related internet resources.
 

marasovec

Member
You can send a string to your website like this
GML:
Code:
http_post = http_post_string("https://x10hosting.com/", "&str="+"yourstring");
PHP:
Code:
$data = $_POST["str"];
 

Gamerev147

Member
You can send a string to your website like this
GML:
Code:
http_post = http_post_string("https://x10hosting.com/", "&str="+"yourstring");
So first I need to get the URL in the create event: http_get("my website")
Then post it to the URL using http_post_string() in Async HTTP event, correct?
 

chamaeleon

Member
So first I need to get the URL in the create event: http_get("my website")
Then post it to the URL using http_post_string() in Async HTTP event, correct?
No. http_get() is not needed if you only need to perform a http_post_string() with its payload, and you call it from some other event (perhaps a step or a mouse or key event, depending on what the trigger is), and you use the async event to determine whether it was successful by examining the response. http_get() has no relevance to what you're trying to do.
 

Gamerev147

Member
So this is what I have so far, all the while it is not working:
Create Event:
Code:
http_post = 0;
url = "http://gamerev147.x10host.com/be/scores.txt";
Key Pressed (Enter):
Code:
http_post = http_post_string(url, "&str=" + "hello world!");
Async HTTP:
Code:
var r_str = "null";

if (ds_map_find_value(async_load, "id") == http_post) {
    
    if (ds_map_find_value(async_load, "status") == 0) {
        
        r_str = ds_map_find_value(async_load, "result");
        show_message(string(r_str));
        
    } else {
        
        show_message("Post failed!");
        
    }
    
}
As I mentioned, this code does not work. Is it my code or the server I'm using?
If it's the server, could anyone recommend a free server that could work with this?

Thanks!
 
H

Homunculus

Guest
You can't simply run a post request to the txt file. You need a script server side (possibly a PHP script) that gets the value, opens your file, and writes whatever info you want into it. You do need to learn a few basic things about PHP, there's no way around it.
 
W

Wheel7Games

Guest
I agree with Catan. There is no way to simply edit a file on a server without a piece of software on the server. That would be a big security issue.
 
W

Wheel7Games

Guest
You can create an Api using .NET (Core) and use a Controller to handle the post action. I am not skilled in PHP, but you can lookup creating a REST service in PHP (or .NET Core).

Either way, you will need to do some server side programming.
 

Gamerev147

Member
You can't simply run a post request to the txt file. You need a script server side (possibly a PHP script) that gets the value, opens your file, and writes whatever info you want into it. You do need to learn a few basic things about PHP, there's no way around it.
Either way, you will need to do some server side programming.
Alright, thank you for your help everyone!
I'll look into PHP Scripts for the server.
 
Top