Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 代理golang https_Authentication_Go_Proxy - Fatal编程技术网

Authentication 代理golang https

Authentication 代理golang https,authentication,go,proxy,Authentication,Go,Proxy,我正在尝试使用代理进行身份验证,我已经传递了头参数 代理授权 但是代理服务器返回 需要代理身份验证 代码: 我必须传递另一个参数 当我执行一次登录时,没有https。。代理身份验证成功。为什么?我找到了解决办法。Golang在方法CONNECT中不传递头参数,则参数代理授权不会发送到代理服务器 为解决此问题,已将字段ProxyConnectHeader添加到结构传输。但这一变化直到发布,这一变化只是在掌握 为了使用master提供的golang来测试这个新领域,我在github上做了一个项目并工

我正在尝试使用代理进行身份验证,我已经传递了头参数

代理授权

但是代理服务器返回

需要代理身份验证

代码:

我必须传递另一个参数


当我执行一次登录时,没有https。。代理身份验证成功。为什么?我找到了解决办法。Golang在方法CONNECT中不传递头参数,则参数代理授权不会发送到代理服务器

为解决此问题,已将字段ProxyConnectHeader添加到结构传输。但这一变化直到发布,这一变化只是在掌握

为了使用master提供的golang来测试这个新领域,我在github上做了一个项目并工作


想分享这篇文章,它很有效:
package main

import (
    "crypto/tls"
    "encoding/base64"
    "fmt"
    "io/ioutil"
    "net/http"
    "net/url"
    "os"
)

func main() {
    req, _ := http.NewRequest("GET", "https://www.google.com.br", nil)
    req.Header.Set("Host", "www.google.com.br")

    proxyURL := url.URL{
        Host: "IP-HERE:PORT-HEERE"}

    transport := &http.Transport{
        Proxy:           http.ProxyURL(&proxyURL),
        TLSClientConfig: &tls.Config{},
    }
    client := &http.Client{Transport: transport}
    req.RequestURI = ""

    auth := fmt.Sprintf("USER:PASSWORD")
    basic := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
    req.Header.Add("Proxy-Authorization", basic)

    resp, err := client.Do(req)
    if err != nil {
        fmt.Printf("erro: %s", err)
    }
    fmt.Printf("code: %s", resp.StatusCode)
    htmlData, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(os.Stdout, string(htmlData))
}