go ghttp 配置代理 配置header

package main

import (
	"github.com/gogf/gf/net/ghttp"
	"net/http"
	"net/url"
	"time"
)

func main() {
	headers := map[string]string{
		"Proxy-Connection": "keep-alive",
		"User-Agent":       "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
		"Content-Type":     "application/x-www-form-urlencoded",
		"Referer":          "https://google.com",
		"NSC_NONCE":        "fuck",
		"Connection":       "close",
		"fuck":             "fuck",
	}
	task := ghttp.NewClient()
	urli := url.URL{}
	urlproxy, _ := urli.Parse("http://127.0.0.1:8080")
	task.Transport = &http.Transport{
		Proxy: http.ProxyURL(urlproxy),
	}
	task.SetTimeOut(time.Second * 15)
	task.SetHeaderMap(headers)
	task.Get("http://www.baidu.com")

}

  

猜你喜欢

转载自www.cnblogs.com/yakoazz/p/12207268.html