获取 net/http: TLS 握手超时 golang

huangapple go评论91阅读模式
英文:

Get net/http: TLS handshake timeout golang

问题

需要你帮助解决这个问题。

package main

import (
	"log"
	"net/http"
)

func main() {
	client := &http.Client{}
	_, err := client.Get("https://www.marathonbet.com/en/")
	if err != nil {
		log.Fatalf("%s\n", err)
	}
}

这段代码一直返回以下错误信息:Get https://www.marathonbet.com/en/: net/http: TLS handshake timeout exit status 1
我尝试了以下方法:

但是都没有成功。所以,请帮助我。

更新:
在 Python 2.7 中,使用 requests 库可以成功执行以下代码:

s = Session()
r = s.get('https://www.marathonbet.com/en/', verify=False)

但是我需要使用 Go 语言来实现。

更新:
问题已解决:只需将 https://www.marathonbet.com/en/ 替换为 https://87.117.250.213/en/,并添加 skip verify。感谢大家的帮助。

英文:

Need your help with this

package main

import (
	"log"
	"net/http"
)

func main() {
	client := &http.Client{}
	_, err := client.Get("https://www.marathonbet.com/en/")
	if err != nil {
		log.Fatalf("%s\n", err)
	}
}

This always return:Get https://www.marathonbet.com/en/: net/http: TLS handshake timeout exit status 1
I`m try:
it
and use this lib
and do it
But nothing works for me..
So, please help me.

Update:
In Python 2.7 with requests this works:

s = Session()
r = s.get('https://www.marathonbet.com/en/, verify=False)

But i need do it with go(

UPD:
Fixed: Just replase https://www.marathonbet.com/en/ to https://87.117.250.213/en/ and adding skip verify.
thx all for help.

答案1

得分: 2

以下是翻译好的内容:

这里是更详细的解释。当你调用一个域名时,你的HTTP客户端会调用一个DNS服务器。DNS服务器会返回目标服务器的IP地址。到这一步,一切都正常。

如果是HTTPS连接,那么就会开始TLS握手。以下是它的工作原理。

获取 net/http: TLS 握手超时 golang

这就是你遇到问题的地方。请求已发送,但服务器没有正确(或根本没有)回应。可能有很多因素导致,比如服务器:

  • 不可访问
  • 需要更多时间来响应
  • 可能被某个防火墙/代理隐藏起来,拒绝连接
  • 阻止来自你的IP地址/位置的所有请求
  • 等等

通过提供skip verify选项并提供明确的IP地址,你可以跳过我上面描述的所有步骤。这意味着:

  • 如果服务器的IP地址发生变化,你的代码将停止工作
  • 如果有人进行中间人攻击,你将无法发现。

如果没有进行更深入的调查,很难找出根本原因。如果你想找出发生了什么,请像@Flowchartsman建议的那样使用httptrace

英文:

Here's a more detailed explanation of what's happening. When you call a domain, your HTTP client calls a DNS server. The DNS server responds with the IP of the target server. At this point everything's OK.

If it's an HTTPS connection, then it starts the TLS handshake. Here's how it works.

获取 net/http: TLS 握手超时 golang

And this the point where you experienced the issue. The request was sent but the server didn't answer correctly (or at all). It may be caused by many factors like the server:

  • isn't accessible
  • needs more time to respond
  • can be hidden behind some firewall/proxy that refuses the connection
  • block all requests from your IP/location
  • etc

By providing the skip verify option and providing the explicit IP address, you skips everything I described above. It means:

  • if the server's IP changes your code will stop working
  • if someone perform a man-in-the-middle attach you won't find out about it.

It's hard to find out what's the root cause without a more deep investigation. If you want to find out what's happening, use the httptrace as @Flowchartsman suggested

huangapple
  • 本文由 发表于 2015年11月7日 09:59:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/33578338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定