避免url使用加号"+"

问题

线上对一个url的请求参数做了加密,突然发现参数的请求值跟解析出来结果不一样,请求参数里面有个“+”号,服务端获取时候变成“ ”,一个空格。

排查

查看nginx日志,发现在nginx获取时候已经是“ ”,于是排除服务端代码问题。经过谷歌,原来url的“+”号,在url解析时候会变成“ ”。

原因

Generally speaking, the plus sign is used as shorthand for a space in query parameters, but while it can be used in such a way in URLs, it isn’t a good idea. The plus sign is sometimes transformed into a space or to “%20” which can cause problems for the spiders crawling your site, hence causing issues with indexation. URLs with spaces are often confusing to theses spiders, especially with forums and blogs where the URL is automatically recofnised and converted into a link.

以上来自 https://www.orchidbox.com/google-recommends-avoidance-of-the-plus-sign-in-your-urls

大意很简单,就是url 的加号可转化成空格或者 “%20”.(“%20就是url空格的编码”),会给使用者带来烦恼。

解决

  1. 避免在url使用+号
  2. 如果类似加密,可能产生加号以及各种特殊符号,建议接口使用post

你可能感兴趣的:(html)