Proxy
设置HTTP客户端发起请求时可以设置代理服务器地址proxyURL
,该该特性使用SetProxy*
相关方法实现。代理主要支持http
和socks5
两种形式,分别为http://USER:PASSWORD@IP:PORT
或socks5://USER:PASSWORD@IP:PORT
形式。
方法列表:
func (c *Client) SetProxy(proxyURL string) func (c *Client) Proxy(proxyURL string) *Client |
我们来看下客户端设置proxyURL
的示例。
使用SetProxy
配置方法。
client := g.Client() client.SetProxy("http://127.0.0.1:1081") client.SetTimeout(5 * time.Second) response, err := client.Get(gctx.New(), "https://api.ip.sb/ip") if err != nil { fmt.Println(err) } response.RawDump() |
使用Proxy
链式方法。
client := g.Client() response, err := client.Proxy("http://127.0.0.1:1081").Get(gctx.New(), "https://api.ip.sb/ip") if err != nil { fmt.Println(err) } fmt.Println(response.RawResponse()) |