Created
June 8, 2023 13:50
-
-
Save parsibox/298a34ea19940ffd1c8571e4bc2e6429 to your computer and use it in GitHub Desktop.
go lang https fix handshake error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"fmt" | |
"log" | |
"net/http" | |
"time" | |
) | |
func main() { | |
client := &http.Client{ | |
Timeout: 10 * time.Second, | |
Transport: &http.Transport{ | |
TLSClientConfig: &tls.Config{ | |
MinVersion: tls.VersionTLS12, | |
CipherSuites: []uint16{ | |
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | |
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | |
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | |
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | |
}, | |
}, | |
}, | |
} | |
req, err := http.NewRequest("GET", "https://www.google.com/", nil) | |
if err != nil { | |
log.Fatalf("%s\n", err) | |
} | |
resp, err := client.Do(req) | |
if err != nil { | |
log.Fatalf("%s\n", err) | |
} | |
defer resp.Body.Close() | |
fmt.Println(resp.Status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment