gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:35:05 24 4
gpt4 key购买 nike

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/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

你能解释一下为什么我得到 curl 52 吗???

在这种情况下,我想寄回 500。我可以这样做吗?

最佳答案

即使缺少 res.send,看起来您的路线也有问题。你可能是说。

app.get('/item/:id', function(...) {
..
})

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

关于Node.js:curl:(52)来自服务器的空回复,请求中的空格未编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18157117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com