Firebase REST API – 如何设置字符编码?

我从Node.js进程调用Firebase REST API。 我看到的问题是,当post正文包含非ASCII字符时,POSTS失败。 尽pipe请求返回了“200”状态,而节点的名称(实际上并没有创build)。

我目前正在尝试这样的事情:

function push(path, object, callback) { console.log("Pushing to "+path+" on: "+firebase.host); var fullPath=firebase.basePath+path; console.log("fullPath="+fullPath); var body = JSON.stringify(object); var options = { host: firebase.host, port: 80, method: "POST", path: fullPath, //gamma.firebase.com/... agent: false, headers: { 'content-type': 'application/json', 'Content-Length': body.length, } }; var req = http.request(options, function(response) { var result = ""; console.dir(response.headers); response.on('data', function(chunk) { result+=chunk; }); response.on('end', function() { console.error("POST response result: "+result); try { callback(JSON.parse(result)); } catch(e) { callback({ error: e }); } }); response.on('error', function(e) { console.error("POST response error: "+error); callback({error: e}); }); }); req.on('error', function(error) { console.error("POST request error: "+error); }); req.write(body); req.end(); } 

“对象”的内容可以像下面这样简单:

 {"text": "test\u00a0text"} 

我回来的结果是状态200,和一个看起来很合理的孩子的名字,实际上并没有创build。

我尝试过将content-type设置为一堆不同的东西(例如,添加; charset =“UTF-8”),而且它似乎没有影响结果。

在处理某些types的input时,会产生错误的200状态,这是错误的。 我们将尽快推出一个解决scheme。 要同时解决此问题,您可以省略发送Content-Length标题。 这将允许您发布ASCII和非ASCII数据。