Created
November 29, 2021 00:00
-
-
Save lucaswxp/b2100671b784d9248781cd0da81fa607 to your computer and use it in GitHub Desktop.
make raw https request in golang using tls
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" | |
"io" | |
"log" | |
) | |
func main() { | |
conn, err := tls.Dial("tcp", "www.google.com:443", &tls.Config{InsecureSkipVerify: true}) | |
if err != nil { | |
panic(err) | |
} | |
defer conn.Close() | |
message := "GET / HTTP/1.1\nHost: www.google.com\nConnection: keep-alive\n\n" | |
n, err := io.WriteString(conn, message) | |
if err != nil { | |
log.Fatalf("client: write: %s", err) | |
} | |
log.Printf("client: wrote %q (%d bytes)", message, n) | |
buf := make([]byte, 512) | |
for { | |
_, err := conn.Read(buf) | |
if err != nil && err.Error() != "EOF" { | |
panic(err) | |
} | |
log.Printf("client: read %s", buf) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment