2016-09-19 17 views
0

Golang的包淨/ HTTP /傳輸可以自動設置Proxy-Authorization頭在Golang淨/ HTTP /運輸代理CONNECT方法頭支撐

func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (*persistConn, error) 

proxyURL, _ := url.Parse("http://username:[email protected]") 
client  := http.Client{Transport: &http.Transport{Proxy:http.ProxyURL(proxyURL)}} 

但我需要提交X標頭到代理服務器。如何自定義傳輸CONNECT方法請求標頭?

net/http/transport

回答

0

這個怎麼樣:

// ... 
request, err := http.NewRequest("GET", "https://www.google.com", nil) 
if err != nil { 
    // do something 
} 
// add header here. 
request.Header.Add("X-Header", "xxx") 

response, err := client.Do(request) 
if err != nil { 
    // do something 
} 
// ... 
+0

這是行不通的,因爲'request.Header'將不會安裝到** ** CONNECT請求。 – Jonathan

+0

我想代理服務器在使用'CONNECT'時不能'看到'請求頭,請點擊這裏:https://stackoverflow.com/questions/10369679/do-http-proxy-servers-modify-request-packets – jsxqf