Skip to content

Using A Proxy

Levi Gross edited this page Jul 23, 2015 · 1 revision

Using A Proxy

Environment Variables

By default, the library uses the golang net/http library which supports proxies via environment variables.

These are set within the shell e.g

export HTTP_PROXY="http://127.0.0.1:8080"
export HTTP_PROXY="https://127.0.0.1:8080"

Or when launching the program

$ HTTP_PROXY=http://127.0.0.1:8080 ./myprog

Using Request Options

RequestsOptions also supports the ability to specify a proxy. The format is protocol:*url.URL please see the example below:

proxyURL, err := url.Parse("http://127.0.0.1:8080") // Proxy URL
if err != nil {
	panic(err)
}

resp, err := grequests.Get("http://www.levigross.com/",
  &grequests.RequestOptions{Proxies: map[string]*url.URL{proxyURL.Scheme: proxyURL}})
Clone this wiki locally