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

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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)