1 回答

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
使用上述評論中提供的信息,這里是一個(gè)關(guān)于如何通過 SOCKS 代理隧道傳輸 HTTP 請求的工作示例:
package main
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"time"
"golang.org/x/net/proxy"
)
func main() {
url := "https://example.com"
socksAddress := "localhost:9998"
socks, err := proxy.SOCKS5("tcp", socksAddress, nil, &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
})
if err != nil {
panic(err)
}
client := &http.Client{
Transport: &http.Transport{
Dial: socks.Dial,
TLSHandshakeTimeout: 10 * time.Second,
},
}
res, err := client.Get(url)
if err != nil {
panic(err)
}
content, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
panic(err)
}
fmt.Printf("%s", string(content))
}
- 1 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)