Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucaswxp/b2100671b784d9248781cd0da81fa607 to your computer and use it in GitHub Desktop.
Save lucaswxp/b2100671b784d9248781cd0da81fa607 to your computer and use it in GitHub Desktop.
make raw https request in golang using tls
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