Forewarning: I’m very new to Haxe.
I’m trying to use http.customRequest
(with the intention of later making PUT and DELETE requests). But when I try to access the result bytes I get a segmentation fault with C++ and a NullPointerException with Java.
I’ve googled for some other uses of customRequest
, and what I’m doing doesn’t seem wrong, but clearly it is.
class Main {
static function main() {
var req = new haxe.Http("https://httpbin.org/put");
var responseBytes = new haxe.io.BytesOutput();
req.onError = function(err) {
trace("onError");
trace(err); // Java says NullPointerException
};
req.onStatus = function(status) {
trace("About to get bytes");
// Removing these lines prevents the errors
var b = responseBytes.getBytes();
trace("Got the bytes");
trace(b.length); // Shouldn't be empty, but is
};
req.customRequest(false, responseBytes, null, "PUT");
}
}
I’ve tried this with the current release and with HEAD (via Brew).
I think my command lines are pretty basic:
$ haxe -cp src -main Main -java bin/java
$ java -jar bin/java/Main.jar
src/Main.hx:12: About to get bytes
src/Main.hx:16: Got the bytes
src/Main.hx:17: 0
src/Main.hx:7: onError
src/Main.hx:8: java.lang.NullPointerException
$ haxe -cp src -main Main -cpp bin/cpp
$ ./bin/cpp/Main
src/Main.hx:12: About to get bytes
src/Main.hx:16: Got the bytes
src/Main.hx:17: 0
[1] 54544 segmentation fault ./bin/cpp/Main
I’d really appreciate any guidance.
(Edit: I originally said that the error trace in Java was causing a NPE, but of course it’s not – that’s just what the error message is.)