当我将以下内容发布到节点时(简化示例):
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:3000/action");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify({path:encodeURIComponent("E:\foo\bar.baz")}));
node.js 代码:
app.post('/action', function (request, response) {
var file = request.body['path'];
console.log(file);
console.log(decodeURIComponent(file));
});
我得到以下输出:
E%3A%0Coo%08ar.baz
E:♀oar.baz
我该如何正确解码?