文章目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)

// http get by proxy
func GetByProxy(url_addr, proxy_addr string) (*http.Response, error) {
request, _ := http.NewRequest("GET", url_addr, nil)
proxy, err := url.Parse(proxy_addr)
if err != nil {
return nil, err
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxy),
},
}
return client.Do(request)
}

func main() {
proxy := "http://58.252.56.149:9000/"
url := "http://www.baidu.com/"
resp, _ := GetByProxy(url, proxy)
fmt.Println(resp)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}

本文引自这里

文章目录