1

I have a url http://127.0.0.1:8000/medicine_alternatives/?id=Avinim%20Plus%20(100%20&%20500)

For clarity ,the parameter without applying encoding is id=Avinim Plus (100 & 500)


At server I am retreiving the parameter as follows:

app.get('/medicine_alternatives', function (req, res) {
    console.log('id='+req.query.id);
});

I am getting id=Avinim Plus (100 in the console .It seems that it is treating everything after & as different parameter.

How do I get the whole string Avinim Plus (100 & 500)?

Flake
  • 1,386
  • 17
  • 31

1 Answers1

1

& is the delimiter for separating query string parameters. A query string parser would parse that as:

{
    "id": "Avinim Plus (100",
    " 500)": undefined
}

Since & is a special character, you need to uriencode it by replace it with %26:

http://127.0.0.1:8000/medicine_alternatives/?id=Avinim%20Plus%20(100%20%26%20500)

Paul
  • 139,544
  • 27
  • 275
  • 264