encode URI (spaces etc.), without encode non-ASCII characters

☆樱花仙子☆ 提交于 2019-12-24 16:09:19

问题


When I use escape/encodeURI/encodeURIComponent to encode URI,
it's encoding special characters (like "? [ ] &" ), and all non-ASCII characters.

I prefer the link to look like:

http:/site.com/?tm=ДОБРОЕ**%20**УТРО  

instead:

http:/site.com/?tm=%u0414%u041E%u0411%u0420%u041E%u0415**%20**%u0423%u0422%u0420%u041E  

My questions:

  1. Is there any need to encode non-ASCII ?
  2. Is there any function that encode only special characters ? (without non-ASCII)

回答1:


  1. Yes.
  2. No.

In http://www.w3.org/Addressing/URL/5_BNF.html one can read:

The "national" and "punctuation" characters do not appear in any productions and therefore may not appear in URLs.



来源:https://stackoverflow.com/questions/9416628/encode-uri-spaces-etc-without-encode-non-ascii-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!