Go语言代码示例

发布时间:2021-12-08 16:16
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "net/http"
  6. "net/url"
  7. )
  8. func main() {
  9. authKey := "请改成您的Key"
  10. password := "请改成您的AuthPwd"
  11. proxyServer := "您的代理IP:端口号"
  12. targetURL := "https://myip.top"
  13. rawURL := fmt.Sprintf("http://%s:%s@%s", authKey, password, proxyServer)
  14. proxyUrl, err := url.Parse(rawURL)
  15. if err != nil {
  16. panic(err)
  17. }
  18. client := http.Client{
  19. Transport: &http.Transport{
  20. Proxy: http.ProxyURL(proxyUrl),
  21. },
  22. }
  23. req, _ := http.NewRequest("GET", targetURL, nil)
  24. rsp, err := client.Do(req)
  25. if err != nil {
  26. fmt.Printf("request failed: %s\n", err)
  27. return
  28. }
  29. defer rsp.Body.Close()
  30. body, err := ioutil.ReadAll(rsp.Body)
  31. if err != nil {
  32. fmt.Println(err)
  33. } else {
  34. fmt.Println(string(body))
  35. }
  36. }
本文导读

客户热线:0771-7711440

微信客服
微信客服
微信二维码