码迷,mamicode.com
首页 > Web开发 > 详细

go ghttp 配置代理 配置header

时间:2020-01-17 21:18:31      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:配置   net   pac   cli   Once   x86   tran   close   highlight   

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")

}

  

go ghttp 配置代理 配置header

标签:配置   net   pac   cli   Once   x86   tran   close   highlight   

原文地址:https://www.cnblogs.com/yakoazz/p/12207268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!