使用Go进行身份验证的代理请求?

huangapple go评论68阅读模式
英文:

Making an authenticated proxy request with Go?

问题

我基本上有一个带有用户名和密码的代理。我想知道如何使用net/http库进行HTTP请求,但是要使用带有身份验证的HTTP代理。

谢谢!

英文:

I basically have a proxy that has a username and password. I was wondering how to make an HTTP request with the library net/http, but with an HTTP proxy with authentication.

Thank you!

答案1

得分: 2

关于这样的代码,可以翻译为:

&http.Client{
  Transport: &http.Transport{
    Proxy: http.ProxyURL(&url.URL{
      Scheme: "http",
      User:   url.UserPassword("login", "password"),
      Host:   "IP:PORT",
    }),
  },
}

这段代码创建了一个HTTP客户端,并设置了代理。代理的地址是"http://IP:PORT",需要进行身份验证,用户名为"login",密码为"password"。

英文:

What about something like

&http.Client{
  Transport: &http.Transport{
    Proxy: http.ProxyURL(&url.URL{
      Scheme: "http",
      User:   url.UserPassword("login", "password"),
      Host:   "IP:PORT",
    }),
  },
}

huangapple
  • 本文由 发表于 2022年4月18日 05:33:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/71905614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定