I am working on a server based on Node.js, using Express.
Use case:
A user should be able to retreive his personal content from the server by making an HTTP GET with the following URL: http://192.168.1.88:3000/content/[userID]
I have defined a route like this:
app.get('/content/:userID', content.MyHandler);
In "MyHandler" I am able to read the userID and return the appropriate data to the user.
The problem is that when "userID" contains a pound sign (#), I only get what is before the # in MyHandler, an consequently I am unable to find who is the user.
So if the userID is "123456", everything is fine. But if the userID is "1234#567", I get only "1234" in MyHandler.
MyHandler looks like this:
exports.MyHandler = function(req, res){
...
var pathChunk = req.url.split("/");
// sys.puts("--> Path in chunks: " + sys.inspect(pathChunk));
// Nothing after # sign
var userID = pathChunk[2]; // Will be incomplete if contains #
};
Is there a way to retreive the full userID value in MyHandler, regardless of the pound (#) sign?
Browsers don't send the hash and everything after to the server.
You need to URL Encode the userID to encode the string in a format that can be passed on the URL line.
This, in javascript would be something like:
var userId_encoded = encodeURIComponent(userId);