Node.js:curl:(52)来自服务器的空回复,请求未编码的空间

GJa*_*ain 6 node.js express

var http = require('http');

var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

server.listen(8000);
console.log("Server running at http://127.0.0.1:8000/");
Run Code Online (Sandbox Code Playgroud)

我按照curl命令执行:

curl "http://127.0.0.1:8000/"
Hello World

// space is not encoded
curl "http://127.0.0.1:8000/x y"
curl: (52) Empty reply from server

curl "http://127.0.0.1:8000/x"
Hello World

// space is encoded
curl "http://127.0.0.1:8000/x%20y"
Hello World
Run Code Online (Sandbox Code Playgroud)

你能解释我为什么卷曲52 ???

在这种情况下,我想送回500.我能这样做吗?

Mor*_*len 1

即使丢失了,res.send看起来你的路线也有问题。你可能是说。

app.get('/item/:id', function(...) {
  ..
})
Run Code Online (Sandbox Code Playgroud)

注意:前面的id. 这将创建一个可以在 req.params.id 上访问的变量。