GMS 2 http_request not sending a GET method

Hello,
I'm trying to send a GET request with http_request, but it sends a POST.
I've wrote this in create:
Code:
var url, headers, data;
url = "http://localhost:3000/";
headers = ds_map_create();
data = ds_map_create();
req = http_request(url, "GET", headers, json_encode(data));
ds_map_destroy(headers);
ds_map_destroy(data);
And this in Async - HTTP:
Code:
show_debug_message("async call");
show_debug_message(ds_map_find_value(async_load, "id"));
if (ds_map_find_value(async_load, "id") == req) {
    var status = ds_map_find_value(async_load, "status");
    show_debug_message(status);
    if (status == 0) {
        show_debug_message(ds_map_find_value(async_load, "http_status"));
        var result = ds_map_find_value(async_load, "result");
        show_debug_message(result);
    }
}
The response comes as "404 - cannot POST".
I've tried with Postman and I got the same result if I used POST method. (Using GET in postman works as should)
For some reason the http_request not accepting GET and converts it to POST.
I've noticed that this problem occurs also with DELETE. It sends a POST method.
Only POST/PUT/PATCH works.
I've managed to get result from the server using http_get. But this function misses headers. And I would prefer to use http_request.

I believe this is a bug?
Any help would be appreciated. Thank you in advance!
 

FrostyCat

Member
GET requests cannot have a body. If you want to pass parameters, you must have them in the URL in URL-encoded form (e.g. http://mysite.com/posts?name=foo&page=2).
 
GET requests cannot have a body. If you want to pass parameters, you must have them in the URL in URL-encoded form (e.g. http://mysite.com/posts?name=foo&page=2).
Thanks for reply. I know that GET cannot have a body request. But GET can have headers. I don't need parameters. I know what I'm looking for.

Are you on Mac per chance? I recently found this issue https://bugs.yoyogames.com/view.php?id=31012
Thanks for reply. And yes, I'm on a Mac. So this issue only occurs with Mac? I'll try with a different platform.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Thanks for reply. And yes, I'm on a Mac. So this issue only occurs with Mac? I'll try with a different platform.
Only on Mac (maybe also iOS if it shares the HTTP request implementation?) and only if you provide a "body" parameter (which you did) - presence of body causes the runtime to send request as POST instead.
 

FrostyCat

Member
Thanks for reply. I know that GET cannot have a body request. But GET can have headers. I don't need parameters. I know what I'm looking for.
Then why aren't you putting your money where your mouth is?

Look at your code:
Code:
data = ds_map_create();
req = http_request(url, "GET", headers, json_encode(data));
That is in every sense trying to give a GET request a non-empty body. An opening brace plus a closing brace does not count as empty. Put an empty string there, not json_encode().
Code:
req = http_request(url, "GET", headers, "");
 
Only on Mac (maybe also iOS if it shares the HTTP request implementation?) and only if you provide a "body" parameter (which you did) - presence of body causes the runtime to send request as POST instead.
Yes, looks like the problem was with "body" that wasn't empty "". Thanks for reply.

Then why aren't you putting your money where your mouth is?

Look at your code:
Code:
data = ds_map_create();
req = http_request(url, "GET", headers, json_encode(data));
That is in every sense trying to give a GET request a non-empty body. An opening brace plus a closing brace does not count as empty. Put an empty string there, not json_encode().
Code:
req = http_request(url, "GET", headers, "");
Sending "" as body solved the issue! And it also works with custom headers. Thank you very much!
 
Top