Created
March 11, 2024 20:15
-
-
Save atoonk/2ed96f863523875b87da3deb1b7143d9 to your computer and use it in GitHub Desktop.
net.dial http get
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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"net" | |
) | |
func main() { | |
// Dial the server | |
conn, err := net.Dial("tcp", "1.1.1.1:80") | |
if err != nil { | |
fmt.Println("Error dialing:", err) | |
return | |
} | |
defer conn.Close() | |
// Send a GET request | |
_, err = conn.Write([]byte("GET / HTTP/1.1\r\nHost: 1.1.1.1\r\n\r\n")) | |
if err != nil { | |
fmt.Println("Error sending request:", err) | |
return | |
} | |
// Read and print the response | |
reader := bufio.NewReader(conn) | |
for { | |
line, err := reader.ReadString('\n') | |
if err != nil { | |
if err != io.EOF { | |
fmt.Println("Error reading response:", err) | |
} | |
break | |
} | |
fmt.Print(line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will connect to 1.1.1.1 port 80
do a GET request and print the reply (301 redirect)