2

Whenever I try to do a GET requests for google.com I get this error:

Get "https://www.google.com/": net/http: HTTP/1.x transport connection broken: malformed HTTP response

I want to try to get the homepage for google and I don't know why this is happening. Someone please help. I am using golang's uTls Here is my code:

func tls_connection(URL string) *http.Response {

    //Creating a cookie jar
    cookieJar, _ := cookiejar.New(nil)

    // Creating the client wrapper
    client := &http.Client{
        Jar: cookieJar,
        Transport: &http.Transport{
            DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
                tcpConn, err := (&net.Dialer{}).DialContext(ctx, network, addr)
                if err != nil {
                    return nil, err
                }
                config := tls.Config{InsecureSkipVerify: true}
                tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_Auto)

                // Parsing the URL for SNI
                u, _ := url.Parse(URL)
                tlsConn.SetSNI(u.Host)

                err = tlsConn.Handshake()
                if err != nil {
                    return nil, fmt.Errorf("uTlsConn.Handshake() error: %w", err)
                }
                return tlsConn, nil
            },
        },
    }

    // Establishes a request
    req, err := http.NewRequest("GET", URL, nil)
    req.Header.Add("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")

    // the client.do wraps the request
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(resp.StatusCode)
        body, _ := ioutil.ReadAll(resp.Body)
        fmt.Println(string(body))
    }
    return resp
}
Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
jjboi8708
  • 65
  • 1
  • 7

0 Answers0