Skip to content

Can UTls be used in conjunction with Http.Client? #367

@shixiawuheng

Description

@shixiawuheng

I have tried multiple solutions and found that no matter what method is used, it seems impossible to establish a connection with the target server. Here is one of them
`
transport := &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
//conn, err := net.Dial(network, addr)
//if err != nil {
// return nil, err
//}

		host, _, err := net.SplitHostPort(addr)
		if err != nil {
			return nil, err
		}

		config := &utls.Config{
			ServerName: host,
			NextProtos: []string{"h2", "http/1.1"}, // 只使用 HTTP/1.1
		}
		dialConn, err := utls.Dial(network, addr, config)
		if err != nil {
			fmt.Printf("net.Dial() failed: %+v\n", err)
			return nil, err
		}

		//tlsConn := tls.Client(dialConn, config)
		//tlsConn := utls.UClient(dialConn, config, version)
		//if err := tlsConn.Handshake(); err != nil {
		//	return nil, err
		//}
		return dialConn, nil
	},
}

return &http.Client{Transport: transport}, nil

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions