func ProxyTest() {
	proxyAddr := "http://your IP:8080/"

	httpUrl := "http://your target url"

	poststr := "your  post values"

	proxy, err := url.Parse(proxyAddr)
	if err != nil {
		log.Fatal(err)
	}

	netTransport := &http.Transport{
		Proxy:                 http.ProxyURL(proxy),
		MaxIdleConnsPerHost:   10,
		ResponseHeaderTimeout: time.Second * time.Duration(5),
	}

	httpClient := http.Client{
		Timeout:   time.Second * 10,
		Transport: netTransport,
	}

	res, err := http.NewRequest("POST", httpUrl, strings.NewReader(poststr))
	if err != nil {
		log.Println(err)
		return
	}

	res.Header.Add("content-type", "application/x-ndjson")

	resp, err := httpClient.Do(res)

	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		log.Println(err)
	}

	c, _ := ioutil.ReadAll(resp.Body)

	fmt.Println(string(c))
}

https://i6448038.github.io/2017/11/11/httpAndGolang/

相关文章:

  • 2021-12-24
  • 2021-08-20
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-09-14
  • 2021-07-04
相关资源
相似解决方案