Rest 如何从Haxe/Neko发送HTTP PUT请求?

Rest 如何从Haxe/Neko发送HTTP PUT请求?,rest,haxe,neko,Rest,Haxe,Neko,我有一个在NekoVM下运行的服务器,它提供类似REST的服务。我正在尝试使用以下Haxe代码向此服务器发送PUT/DELETE请求: static public function main() { var req : Http = new Http("http://localhost:2000/add/2/3"); var bytesOutput = new haxe.io.BytesOutput(); req.onData = function (data)

我有一个在NekoVM下运行的服务器,它提供类似REST的服务。我正在尝试使用以下Haxe代码向此服务器发送PUT/DELETE请求:

static public function main()
{
    var req : Http = new Http("http://localhost:2000/add/2/3");
    var bytesOutput = new haxe.io.BytesOutput();

    req.onData = function (data)
    {
        trace(data);
        trace("onData");
    }

    req.onError = function (err)
    {
        trace(err);
        trace("onError");
    }

    req.onStatus = function(status)
    {
        trace(status);
        trace("onStatus");
        trace (bytesOutput);
    }

    //req.request(true); // For GET and POST method

    req.customRequest( true, bytesOutput , "PUT" );

}
问题是只有
onStatus
事件显示了以下内容:

Main.hx:32: 200
Main.hx:33: onStatus
Main.hx:34: { b => { b => #abstract } }

谁能解释一下我对
customRequest
的错误吗?

customRequest
不调用
onData


customRequest
调用完成后,调用了
onError
,或者首先调用了
onStatus
,然后将响应写入指定的输出。

对于那些找到这些答案(正确答案)并想知道完成的代码可能是什么样子的人:

static public function request(url:String, data:Any) {
    var req:Http = new haxe.Http(url);
    var responseBytes = new haxe.io.BytesOutput();

    // Serialize your data with your prefered method
    req.setPostData(haxe.Json.stringify(data)); 
    req.addHeader("Content-type", "application/json");

    req.onError = function(error:String) {
        throw error;
    };

    // Http#onData() is not called with custom requests like PUT

    req.onStatus = function(status:Int) {
        // For development, you may not need to set Http#onStatus unless you are watching for specific status codes
        trace(status);
    };

    // Http#request is only for POST and GET
    // req.request(true);

    req.customRequest( true, responseBytes, "PUT" );

    // 'responseBytes.getBytes()' must be outside the onStatus function and can only be called once
    var response = responseBytes.getBytes();

    // Deserialize in kind
    return haxe.Json.parse(response.toString());
}

我提出了一个

customRequest可能是异步的,所以在退出main()函数之前,您可能需要等待回调一点时间?我尝试在customRequest之后添加一个Sys.Sleep(秒)。但没别的了。值得注意的是,request(true)是从Haxe源调用customRequest。根据框架的不同,休眠程序也可能会阻止回调。您有onData的工作示例吗?如果我注释
customRequest
并取消注释
request(true)
onData正在工作,您的自定义请求可能无效?您可以使用其他工具(如)尝试请求吗?