Setting up proxy for HTTP client

后端 未结 5 2071
抹茶落季
抹茶落季 2020-12-12 18:15

I\'m trying to setup the HTTP client so that it uses a proxy, however I cannot quite understand how to do it. The documentation has multiple reference to \"proxy\" but none

5条回答
  •  攒了一身酷
    2020-12-12 18:52

    Go will use the the proxy defined in the environment variable HTTP_PROXY if it's set. Otherwise it will use no proxy.

    You could do it like this:

    os.Setenv("HTTP_PROXY", "http://someip:someport")
    resp, err := http.Get("http://example.com")
    if err != nil {
        panic(err)
    }
    

提交回复
热议问题