Skip to content

Instantly share code, notes, and snippets.

@progala
Created February 7, 2022 15:05
Show Gist options
  • Save progala/170bb98a0c87c9ca1d88e2aa95a9ffe9 to your computer and use it in GitHub Desktop.
Save progala/170bb98a0c87c9ca1d88e2aa95a9ffe9 to your computer and use it in GitHub Desktop.
Use net.Dial to connect to a website
package main
import (
"bufio"
"fmt"
"net"
)
func main() {
conn, err := net.Dial("tcp", "duckduckgo.com:80")
if err != nil {
panic(err)
}
fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
scanner := bufio.NewScanner(bufio.NewReader(conn))
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Printf("%s\n", scanner.Text())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment