Skip to content

Instantly share code, notes, and snippets.

@manigandand
Created July 19, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manigandand/997d5d447bb4bde417c02a1ff1fcb67e to your computer and use it in GitHub Desktop.
Save manigandand/997d5d447bb4bde417c02a1ff1fcb67e to your computer and use it in GitHub Desktop.
golang client proxy
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
)
func main() {
// get free proxy address from here: https://free-proxy-list.net/
//creating the proxyURL
proxyStr := "http://138.118.85.25:53281"
proxyURL, err := url.Parse(proxyStr)
if err != nil {
log.Println(err)
}
fmt.Printf("%+v\n\n", proxyURL)
// creating proxy client
proxyClient := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
},
}
//creating the URL to be loaded through the proxy
urlStr := "https://www.kaggle.com/nikelin"
kaggleURL, err := url.Parse(urlStr)
if err != nil {
log.Println(err)
}
//generating the HTTP GET request
request, err := http.NewRequest("GET", kaggleURL.String(), nil)
if err != nil {
log.Println(err)
}
fmt.Printf("%+v\n\n", request)
//calling the URL
response, err := proxyClient.Do(request)
if err != nil {
log.Println(err)
}
//getting the response
data, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Println(err)
}
//printing the response
log.Println(string(data))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment