go POST请求的时候设置http代理,代码直接贴出来
req, _ := http.NewRequest("POST", "http://www.baidu.com",
strings.NewReader(fmt.Sprintf("username=admin&password=%s", "123123")))
//HTTP代理
proxy := "http://127.0.0.1:1080/"
proxyAddress, _ := url.Parse(proxy)
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyAddress),
},
}
resp, err := client.Do(req)
body, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
fmt.Println(string(body))
直接使用就可以