Angular url plus sign converting to space

后端 未结 7 1572
梦如初夏
梦如初夏 2020-11-29 06:02

I have angular application where i want to pass plus sign + in query string like:

http://localhost:3000/page?name=xyz+manwal
7条回答
  •  攒了一身酷
    2020-11-29 06:43

    This is a quite common problem. You can pass it normally in application/x-www-form-urlencoded request. No other request will be able to correctly parse +. They will always parse it into %20 instead of %2B.

    You would need to manually manipulate the query parameter, there are 2 ways:

    • Encode the parameter into base64 encoding, this way no special character can break you application, but you would need to handle it also on the receiving part (decoding).
    • A simplier solutions would be, before hitting the URL, replace all + signs with %2B. This way the other side will be able to decode it normaly, without the need of a special routine.

    For more info you should reffer to hthe following stack overflow questions Android: howto parse URL String with spaces to URI object? and URL encoding the space character: + or %20?

提交回复
热议问题