简体   繁体   English

何时使用HTTP代理

[英]When to use HTTP Proxy

I am having trouble understanding ProxyFromEnvironment and ProxyURL in net/http package. 我在理解net / http包中的ProxyFromEnvironmentProxyURL时遇到问题。 Can someone please explain me when and why these two functionalities are used? 有人可以解释我何时以及为什么使用这两种功能吗?

My current understanding (at least for ProxyFromEnvironment) is that this is used to get the URL of a PROXY Server from the Environment Variables and this PROXY Server is used to make HTTP Requests. 我目前的理解(至少对于ProxyFromEnvironment而言)是,这用于从环境变量获取PROXY服务器的URL,而该PROXY服务器用于发出HTTP请求。

Both functions are related to how you use the http.Transport mechanism. 这两个功能都与您使用http.Transport机制的方式有关。

One can be used to allow the transport to dynamically retrieve the proxy settings from the environment, the other can be used to provide a static URL to be used by the transport for the proxy every time. 一个可以用来允许传输从环境中动态检索代理设置,另一个可以用来提供静态URL,以供传输每次用于代理。

ProxyFromEnvironment is a func that returns a URL describing the proxy that is configured in the Environment; ProxyFromEnvironment是一个函数,它返回描述环境中配置的代理的URL。 it can be assigned to the Transport.Proxy field, and every time the Transport makes a request, the Proxy will depend on the values in the Environment. 可以将其分配给Transport.Proxy字段,并且每次Transport发出请求时,Proxy都将取决于Environment中的值。

ProxyURL is a func that returns a general func which returns the given URL every time it is invoked; ProxyURL是一个函数,它返回一个常规函数,该函数在每次调用时都返回给定的URL。 it can be used to generate a helper function to assign to the Transport.Proxy field, so that your Transport has a consistent Proxy every time the Transport makes a request. 它可以用于生成一个辅助函数,以分配给Transport.Proxy字段,以便每次Transport发出请求时,您的Transport都具有一致的Proxy。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM