package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
// 设置代理
os.Setenv("HTTP_PROXY", "http://127.0.0.1:8899")
os.Setenv("HTTPS_PROXY", "https://127.0.0.1:9743")
c := http.Client{
// Transport: &http.Transport{
// Proxy: http.ProxyURL(urlproxy),
// },
}
reqest, _ := http.NewRequest("GET", "http://www.httpbin.org/",nil)
resp,err:=c.Do(reqest)
if err != nil {
fmt.Println(err.Error())
}
defer c.CloseIdleConnections()
//defer resp.Close
body,_:=ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
网友评论