Go语言代码示例
发布时间:2021-12-08 16:16
package mainimport ("fmt""io/ioutil""net/http""net/url")func main() {authKey := "请改成您的Key"password := "请改成您的AuthPwd"proxyServer := "您的代理IP:端口号"targetURL := "https://myip.top"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))}}