我想做什么:
构建一个包(以备后用),提供一种方法通过给定的socks5代理执行对任何页面的get请求。
我的问题:
每当我尝试使用SSL (https)请求页面时,就会出现以下错误:
执行请求Get https://www.xxxxxxx.com时出错:socks连接tcp 83.234.8.214:4145->www.xxxxxxx.com:443: EOF
然而,使用http://www.google.com
请求是正常的。所以SSL连接肯定有问题。我不知道为什么这不起作用,因为我对SSL连接经验不是很丰富。文件结束
对我来说没有意义。
我的当前代码:
func main() {
// public socks5 - worked when I created this question
proxy_addr := "83.234.8.214:4145"
// With this address I get the error
web_addr := "https://www.whatismyip.com"
// Requesting google works fine
//web_addr := "http://www.google.com"
dialer, err := proxy.SOCKS5("tcp", proxy_addr, nil, proxy.Direct)
handleError(err, "error creating dialer")
httpTransport := &http.Transport{}
httpClient := &http.Client{Transport: httpTransport}
httpTransport.DialTLS = dialer.Dial
req, err := http.NewRequest("GET", web_addr, nil)
handleError(err, "error creating request")
httpClient.Timeout = 5 * time.Second
resp, err := httpClient.Do(req)
handleError(err, "error executing request")
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
handleError(err, "error reading body")
fmt.Println(string(b))
}
func handleError(err error, msg string) {
if err != nil {
log.Fatal(err)
}
}
那么我在处理ssl连接方面缺少什么?
非常感谢。
编辑1:
如果有人认为这是whatismyip.com
的问题,我已经进行了更多测试:
- https://www.google.com
- EOF错误
- https://stackoverflow.com
- EOF错误
- https://www.youtube.com/
- EOF错误
http
而不是https
。我已经尝试过使用您的代码和https://www.google.com
,但也无法正常工作... - math2001<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
。 - Michael Hampton