当我将以下内容发布到node (简化示例)时:
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我怎么才能正确解码呢?
发布于 2012-11-20 02:24:28
您在路径中编码special characters,因为反斜杠是为转义保留的:
\f Form feed
\b Backspace
经过编码后,这些内容将变为:
%0C
%08
来自MDN
若要在字符串中包含文字反斜杠,则必须转义反斜杠字符
"E:\\foo\\bar.baz"
https://stackoverflow.com/questions/13459515
复制相似问题