Ssl Golang:使用tls.dial的https请求

Ssl Golang:使用tls.dial的https请求,ssl,go,https,proxy,request,Ssl,Go,Https,Proxy,Request,我正在尝试与golang进行https请求 conf := &tls.Config{ InsecureSkipVerify: true, MinVersion:tls.VersionTLS10, } //TLS connection tlsCon, err := tls.Dial("tcp", "youtube.com:443", conf) if err != nil { fmt.Println("SSL Error : " + err.Error())

我正在尝试与golang进行https请求

conf := &tls.Config{
    InsecureSkipVerify: true,
    MinVersion:tls.VersionTLS10,
}
//TLS connection
tlsCon, err := tls.Dial("tcp", "youtube.com:443", conf)
if err != nil {
    fmt.Println("SSL Error : " + err.Error())
    return
}

defer tlsCon.Close()

state := tlsCon.ConnectionState()
fmt.Println("SSL ServerName : " + state.ServerName)
fmt.Println("SSL Handshake : ", state.HandshakeComplete)
fmt.Println("SSL Mutual : ", state.NegotiatedProtocolIsMutual)

request = '
CONNECT youtube.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101       Firefox/51.0
Proxy-Connection: close
Connection: close
Host: youtube.com:443

'

n, err = io.WriteString(tlsCon, request)
if err != nil {
    fmt.Println("SSL Write error :", err.Error(), n)
}

n, err = tlsCon.Read(data)
if err != nil {
    fmt.Println("SSL Read error : " + err.Error())
    return
}
这是我的代码,state.HandshakeComplete,state.negotiatedProtocolisum实际返回true,state.ServerName返回=“”

当我将数据写入tls连接时,没有错误返回,tls连接也不会回复我的请求


任何帮助都表示感谢。谢谢。

为什么不使用
http.Client
+
http.Transport
(对于TLS参数)+
http.NewRequest
?我将实现我自己的基本http/https服务器。我实现http时没有出错,而且速度非常快,但是当涉及到https时,我遇到了麻烦。ServerName字段文档说:
//客户端请求的服务器名称,如果有的话(仅限于服务器端)
,您在请求中没有设置服务器名称,而是在客户端。你看了吗?