英文:
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",
}),
},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论