json - GameMaker runner crashes when making HTTP requests -


i got using gamemaker:studio, , hoo boy have there been massive updates since last used it! in fact last time used had windows , html5 export options...

anyway, eager try out of new stuff, decided take shot @ native http functions, since looked promising.

i did test using http_post_string() great effect, sending json string server , getting json string back. returned string represented object single property, "echo", contained http request had been made, see gm:s sending.

i didn't sent content-type: application/x-www-form-urlencoded when quite json, , wanted ability set own user agent string server know game talking without having pass parameter.

so re-created same request using lower-level http_request() function. looked fine, tested it.

it crashed. like, no error messages or anything, total crash , windows had force-close it.

so here code rights should work fine, crashes when run...

///send_request(file,ds_map_data,callback_event_id) var request = ds_map_create(); request[? "instance"] = id; request[? "event"] = argument2;  if( !instance_exists(obj_ajax_callback)) {     instance_create(0,0,obj_ajax_callback); }  var payload = json_encode(argument1); var headers = ds_map_create(); headers[? "content-length"] = string_length(payload); headers[? "content-type"] = "application/json"; headers[? "user-agent"] = obj_ajax_callback.uastring;  var xhr = http_request("https://example.com/"+argument0,"post",headers,payload);  with(obj_ajax_callback) {     active_callbacks[? xhr] = request; }  ds_map_destroy(headers); 

obj_ajax_callback object maintains ds_map of active requests, , in http event listens requests' callbacks , reacts along lines of with(request[? "instance"]) event_user(request[? "event"]) calling object can handle response. hasn't changed working http_post_string() attempt.

any idea causing crash?

the reason why crashes because sending content-length header real instead of string. if change line to

headers[? "content-length"] = string(string_length(payload)); 

it should work.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -