How to make a synchronous POST request to `url`?

https://api.haxe.org/haxe/Http.html#requestUrl
staticrequestUrl (url:String):String

This creates a new Http instance and makes a GET request by calling its request(false) method.
If url is null, the result is unspecified.

I need to make POST request but i dont need to make this callbacks in example

how i can do it?

You need to create the http object var request = new haxe.Http(url);, then optionally set the post data using request.setPostData(data); and finally send the request with request.request(true);.

i already do this
but how to get response content?

request (?post:Bool):Void
this method didnt return content

You need to set the onData variable, for instance:

var response = "";
request.onData = function (data) {
    response = data;
}
request.request(true);
// now you have response filled

You may want to set onError too do deal with errors.

ок
i have other problem

var result = ‘’;
req.onData = function (data:String)
{
trace(data);
}
req.onError = function (error)
{
trace(req);
trace(error);
trace(‘error’);
}
req.request(true);

for error http request i got only short error msg

Main.hx:28: haxe.Http
Main.hx:29: Http Error #400
Main.hx:30: error

how to get all responsetext of error response? like in onData handler?

rest api server turn error content in response like {“error”: SOME_ERROR_CODE, “error_description”: “blablabla”}
and status 400

how to get this error content?

error is already a string here, it’s the message you’re receiving.

Maybe you need to pass the accept header in order to get the json response?
Something like req.addHeader('accept', 'application/json')

not work - same error

Main.hx:28: haxe.Http
Main.hx:29: Http Error #400
Main.hx:30: error

how to get response content? (req.responseText not work too)

same ploblem - status closed

but not implemented?

this works

req.responseData

1 Like