Which parts of a URL need to be encoded?

旧时模样 提交于 2020-01-16 06:09:26

问题


With POST is easy and automatic: just use application/x-www-form-urlencoded or multipart/form-data or whatever.

Instead, what parts should be encoded in a GET request?

The whole query string? Just the parameter values but not the names? And the fragment?

Maybe also the path? But am pretty sure that I shouldn't encode the host or the scheme (since there are encoding and specs for international domains, like in japanese etc.). Hence the question is more about the URI 😉


Strangely I didn't find a clear specific answer to it on SO, nor it's easy to find one on the net.


回答1:


We have to encode the parts of the url (excluding the domain name) that may contain symbols and non ASCII characters excluding the slashes “/“ and the operands used by query strings (?, = and &).

Note: if you encode all the second part of the url together including the slashes and the operands used by the query strings, this part will be considered all as a single value and the url may not work properly.



来源:https://stackoverflow.com/questions/51292397/which-parts-of-a-url-need-to-be-encoded

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