2018-09-20 15:55
浏览 739

Http通过socks5获取请求| EOF错误

What I'm trying to do:
Build a package (later usage) that provides a method to execute a get-request to any page through a given socks5 proxy.

My problem:
When ever I try to request a page with SSL (https) I get the following error:

Error executing request Get https://www.xxxxxxx.com: socks connect tcp>www.xxxxxxx.com:443: EOF

However requesting http://www.google.com is working fine. So there must be a problem with the SSL connection. Can't imagine why this isn't working as I'm not very experienced with SSL-connections. End of file makes no sense to me.

My current code:

func main() {
    // public socks5 - worked when I created this question
    proxy_addr := ""

    // 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")


func handleError(err error, msg string) {
    if err != nil {

So what am I missing in here to deal with ssl-connections?

Thank you very much.

Edit 1:

In case someone would think this is an issue with whatismyip.com I've done some more tests:

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongyingtang3803 2018-09-28 11:05

    Connection between your program and your socks5 proxy goes not through SSL/TLS

    So you should change line
    httpTransport.DialTLS = dialer.Dial
    httpTransport.Dial = dialer.Dial

    I checked https://www.whatismyip.com and https://www.google.com. URLs are downloaded fine.
    For test I set up 3proxy service on my server, test your code with fixed line and check 3proxy logs.

    All made requests was in proxy server logs.

    If you need more help - please let me know, I'll help

    Things to notice:

    • Socks5 proxies need to support SSL connections.
    • The code from the question won't work with this answer as the proxy (used in the code) isn't supporting SSL connections.
    解决 无用
    打赏 举报

相关推荐 更多相似问题