英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论