帮助中心

go语言如何接入代码demo

go语言启用资源:

package main


import (

"fmt"

"io/ioutil"

"net/http"

"net/url"

)


//sock5

func socksproxy() {

urli := url.URL{}

urlproxy, _ := urli.Parse("http://测试:端口")

client := &http.Client{

Transport: &http.Transport{

Proxy: http.ProxyURL(urlproxy),

},

}

rqt, err := http.NewRequest("GET", "http://myip.top", nil)

if err != nil {

println("接口获取失败!")

return

}


rqt.Header.Add("User-Agent", "Lingjiang")

//处理返回结果

response, _ := client.Do(rqt)

defer response.Body.Close()

body, err := ioutil.ReadAll(response.Body)

if err != nil {

return

}


fmt.Println("socks5:", string(body))

return


}


//http代理

func httpproxy() {

urli := url.URL{}

urlproxy, _ := urli.Parse("http://测试:端口")

client := &http.Client{

Transport: &http.Transport{

Proxy: http.ProxyURL(urlproxy),

},

}

rqt, err := http.NewRequest("GET", "http://myip.top", nil)

if err != nil {

println("接口获取失败!")

return

}


rqt.Header.Add("User-Agent", "Lingjiang")

//处理返回结果

response, _ := client.Do(rqt)

defer response.Body.Close()

body, err := ioutil.ReadAll(response.Body)

if err != nil {

return

}


fmt.Println("http:", string(body))

return


}


//本机地址

func httplocal() {

client := &http.Client{}

rqt, err := http.NewRequest("GET", "http://myip.top", nil)

if err != nil {

println("接口获取失败!")

return

}


rqt.Header.Add("User-Agent", "Lingjiang")

//处理返回结果

response, _ := client.Do(rqt)

defer response.Body.Close()

body, err := ioutil.ReadAll(response.Body)

if err != nil {

return

}


fmt.Println("本机:", string(body))

return


}

func main() {

httplocal()

httpproxy()

socksproxy()

}