Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: curl: (52) Empty reply from server with space in request not encoded

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/");

I executed following curl commands:

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

Can you please explain the why I get curl 52???

In this case, I want to send 500 back. Can I do that?

like image 249
GJain Avatar asked Aug 09 '13 23:08

GJain


1 Answers

Even with the missing res.send it looks like an issue with your route. you probably meant.

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

Note the : before id. This creates a variable that can be accessed on req.params.id.

like image 118
Morgan ARR Allen Avatar answered Oct 17 '22 02:10

Morgan ARR Allen