2021-06-12

Encrypted Alert

func TLSClient() {
	//log.SetFlags(log.Lshortfile)
	//conf := &tls.Config{
	//	InsecureSkipVerify: true,
	//}
	//host := "127.0.0.1:8000"
	host := "www.baidu.com:443"
	//conn, err := tls.Dial("tcp", host, conf)
	conn, err := tls.Dial("tcp", host, nil)
	if err != nil {
		log.Println(err)
		return
	}
	defer conn.Close()
	data := "GET / HTTP/1.1\nHost: www.baidu.com\nUser-Agent: Go-http-client/1.1\r\n\r\n"
	n, err := conn.Write([]byte(data))
	if err != nil {
		log.Println(n, err)
		return
	}
	buf := make([]byte, 2048)
	n, err = conn.Read(buf)
	if err != nil {
		log.Println(n, err)
		return
	}
	println(string(buf[:n]))
}

建立了 TLS 连接,但是发送了明文,所有会被拒绝,不能按照预期请求到报文。

上一篇:【Go】用 Go 访问 MySQL


下一篇:IOS 处理空字符串