golang url解析问题

用golang开启httpserver,如果参数里面有(;)这个符号的话会作为字段值结束,然后分拆出来多一个参数。这个是怎么解决?
即如果我传的是params=111;222
然后golang就解析成两个参数[params=111,222=]

阅读 5.6k
2 个回答

;是HTTP URL中的特殊字符RFC
解决方案

  1. 更换分隔符号

  2. 使用URL Encoder将参数编码,在JS中可以使用encodeURIComponent

Many URL schemes reserve certain characters for a special meaning:
   their appearance in the scheme-specific part of the URL has a
   designated semantics. If the character corresponding to an octet is
   reserved in a scheme, the octet must be encoded.  The characters ";",
   "/", "?", ":", "@", "=" and "&" are the characters which may be
   reserved for special meaning within a scheme. No other characters may
   be reserved within a scheme.

只能换分隔符了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题