Golang:带有tls.dial的https请求

i am trying to make https request with golang.

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
}

this is my code , state.HandshakeComplete, state.NegotiatedProtocolIsMutual returns true and state.ServerName returns = ''

when i write data to tls connection no error returns also tls connection never reply my request.

any help appricated. thanks.

dsc56927
dsc56927 ServerName字段文档说////客户端请求的服务器名称(如果有)(仅服务器端),您未在请求中设置服务器名称,而您位于客户端。您是否看过http.Transport如何创建连接?
3 年多之前 回复
doupo1890
doupo1890 我要实现自己的基本http/https服务器。我没有错误也实现了http实现,但它也非常快,但是当涉及到https时我就卡住了。
3 年多之前 回复
duanfan1965
duanfan1965 为什么不使用http.Client+http.Transport(用于TLS参数)+http.NewRequest?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐