Include %2F in golang http.NewRequest

huangapple go评论69阅读模式
英文:

Include %2F in golang http.NewRequest

问题

当我尝试使用%2F在http.NewRequest中包含一个"/"时,它在调用url.Parse()时会将其转换回"/"。有没有办法阻止这种情况发生?我尝试将百分比转换为%25,但仍然不起作用。

你可以在这里看到:
http://play.golang.org/p/YOnktREbbf

英文:

When I try and include a "/" by using %2F in http.NewRequest, it converts it back into "/" when it calls url.Parse(). Is there any way to prevent this? I tried converting the percent to %25, but it still doesn't work.

You can see it here:
http://play.golang.org/p/YOnktREbbf

答案1

得分: 5

这是Go标准库设计上的一个缺陷。已经被确认(问题3659),但出于向后兼容性的考虑,他们决定不修复它。

虽然这并不好玩,但最好的方法是使用opaque构建URL。你可以在这里找到文档。

英文:

This is a flaw in the design of the Go standard library. It has been acknowledged (issue 3659), but they have decided not to fix it for backwards compatibility reasons.

Although it isn't fun, the best way is to build a URL using opaque. You can find documentation here.

huangapple
  • 本文由 发表于 2015年2月15日 08:11:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/28521723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定