package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
authKey := "请改成您的Key"
password := "请改成您的AuthPwd"
proxyServer := "您的代理IP:端口号"
targetURL := "https://test.ipw.cn"
// 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing
rawURL := fmt.Sprintf("http://%s:%s@%s", authKey, password, proxyServer)
proxyUrl, err := url.Parse(rawURL)
if err != nil {
panic(err)
}
client := http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
},
}
req, _ := http.NewRequest("GET", targetURL, nil)
rsp, err := client.Do(req)
if err != nil {
fmt.Printf("request failed: %s\n", err)
return
}
defer rsp.Body.Close()
body, err := ioutil.ReadAll(rsp.Body)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(string(body))
}
}