Created
July 19, 2018 10:21
-
-
Save manigandand/997d5d447bb4bde417c02a1ff1fcb67e to your computer and use it in GitHub Desktop.
golang client proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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