私は、Goでプロキシ経由で作業していたクライアントからGETリクエストを作成しようとしていました。httpsリクエストを行うときに、Goのhttpクライアントがプロキシ経由でUnauthorizedを返すのはなぜですか?
カール同等のビット次のようになります。このような何かが動作しますが、移動中に相当していないよう
curl -v -x example.proxy.com:8080 -U username:password 'https://example.com'
、ここでの例です:
auth := "username:password"
basic := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
proxyURL, _ := url.Parse("http://example.proxy.com:8080")
url, _ := url.Parse("https://example.com")
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
client := &http.Client{
Transport: transport,
}
request, _ := http.NewRequest("GET", url.String(), nil)
request.Header.Add("Proxy-Authorization", basic)
request.Header.Add("Proxy-Connection", "Keep-Alive")
response, _ := client.Do(request)
2つの唯一の違いは、httpとhttpsの両方のURLにリクエストを行うときにcurlコマンドが成功し、Goコードがhttpで動作するが、上記の例(https://example.com
、または他のhttps URL)では、t彼はUnauthorizedのステータスを返します。
私はここで本当に明白な何かを見逃しているように感じますが、その底に達するようには見えません。
また、「Proxy-Connection:keep-alive」ヘッダーは必要ありません。これは "Connection"と重複しており、古いHTTP/1.0プロキシだけが必要です。 – JimB