且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

golang - HTTP客户端总是转义该URL

更新时间:2022-02-22 21:36:28

您可以设置一个不透明的网址。

You can set an opaque url.

假设您希望url指向 http://example.com/test(a),您可以这样做:

Assuming you want the url to point to http://example.com/test(a) you would want to do:

req.NewRequest("GET", "http://example.com/test(a)", nil)
req.URL = &url.URL{
    Scheme: "http",
    Host:   "example.com",
    Opaque: "//example.com/test(a)",
}
client.Do(req)

示例:http://play.golang.org/p/09V67Hbo6H

文档: http://golang.org/pkg/net/url/#URL