Golang:使用tls.dial https请求

时间:2017-03-07 10:03:10

标签: 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())
    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.NegotiatedProtocolIsMutual返回true,state.ServerName返回=''

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

任何有用的帮助。感谢。

0 个答案:

没有答案