-1

I have a firebase function doing a http GET. There are 3 parameters and all works ok but if one of the parameters contains acentuation the Firebase console don't show any error but the the GET is not executed. In this case, the problem is with Parameter03.

        var url = 'http://myapi.azurewebsites.net/api/values?Parameter01=' + nameParam + '&Parameter02=' + emailParam + '&Parameter03=' + serviceParam ;

http.get(url, (resp) => {
     res.setEncoding('utf8');
}).on("error", (err) => {
  console.log("Error : " + err.message);
});

Any help please ?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
GCoe
  • 849
  • 4
  • 14
  • 30

1 Answers1

1

Whenever you build a URL, you should properly escape all the query string components so that they contain only valid characters. That's what encodeURIComponent() is for. So do encode all your query string values like this instead:

var url = 'http://myapi.azurewebsites.net/api/values' +
    '?Parameter01=' + encodeURIComponent(nameParam) +
    '&Parameter02=' + encodeURIComponent(emailParam) +
    '&Parameter03=' + encodeURIComponent(serviceParam);

There are other cleaner ways to build a URL with query string components, but this should work fine.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thank you Doug. Worked. Another alternative is to clean the parameters before like in const serviceParam = servicoParamComAcentos.normalize('NFD').replace(/[\u0300-\u036f]/g, "") – GCoe Nov 18 '18 at 22:55