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

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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack