2

I am having a rest API where end point is like this:

/private/items/query

where I am taking id as query param so url is like:

http://localhost:8081/private/items/query?id=item1234

Now when the item contains % symbol its not reaching as query param in my APIs properly e.g. in case of item%21 what I am receiving is item!.

How can this problem be fixed?

akhil_mittal
  • 23,309
  • 7
  • 96
  • 95

1 Answers1

4

The % symbol is generally used to encode special characters in query string e.g. + is encoded to %2B while sending as query string.

As mentioned [here][1]:

Because the percent ("%") character serves as the indicator for percent-encoded octets, it must be percent-encoded as "%25" for that octet to be used as data within a URI.

In your case you need to send %2521 which will be decoded to %21 at the backend as %25 is % when url-decoded. You can use this [link][2] for url-encoding purpose. [1]: https://www.rfc-editor.org/rfc/rfc3986#section-2.4 [2]: https://www.urlencoder.org/

Community
  • 1
  • 1
rakhi
  • 262
  • 2
  • 8