-
Notifications
You must be signed in to change notification settings - Fork 139
Using A Proxy
Levi Gross edited this page Jul 23, 2015
·
1 revision
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
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}})
Please see GoDocs for a list of basic examples