Node.js:curl:(52)来自服务器的空回复,请求中的空间不被编码
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/");
我执行了下面的curl命令:
curl "http://127.0.0.1:8000/" Hello World // space is not encoded curl "http://127.0.0.1:8000/xy" 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
你能解释为什么我curl52?
在这种情况下,我想发回500。 我可以这样做吗?
即使缺lessres.send
它看起来像你的路线问题。 你可能的意思。
app.get('/item/:id', function(...) { .. })
注意:
在id
之前。 这会创build一个可以在req.params.id上访问的variables。
我也有这个问题。 我猜curl
期望已编码的url,如果引用双引号。 如果在url中发现空白,它会认为它是一个无效的url。
这与wget
命令完全不同。 如果你运行这个:
wget "http://127.0.0.1:8000/xy"
实际上wget为你编码的url,实际上这个请求会被发送为:
http://127.0.0.1:8000/x%20y
这些事实真的让我们绞尽脑汁。