draj30958
2018-09-20 15:55
浏览 712
已采纳

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 83.234.8.214:4145->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 := "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)
    }
}

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
    to
    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.
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题