2020-11-15 23:54:47 +03:00
|
|
|
import net
|
|
|
|
import io
|
2020-08-21 00:01:37 +03:00
|
|
|
|
2020-12-15 18:39:11 +03:00
|
|
|
fn main() {
|
|
|
|
// Make a new connection
|
2021-01-26 17:43:10 +03:00
|
|
|
mut conn := net.dial_tcp('google.com:80') ?
|
|
|
|
defer {
|
|
|
|
conn.close() or { }
|
|
|
|
}
|
2020-12-15 18:39:11 +03:00
|
|
|
// Simple http HEAD request for a file
|
2021-01-26 17:43:10 +03:00
|
|
|
conn.write_str('HEAD /index.html HTTP/1.0\r\n\r\n') ?
|
2020-12-15 18:39:11 +03:00
|
|
|
// Read all the data that is waiting
|
2021-01-26 17:43:10 +03:00
|
|
|
result := io.read_all(reader: conn) ?
|
2020-12-15 18:39:11 +03:00
|
|
|
// Cast to string and print result
|
|
|
|
println(result.bytestr())
|
|
|
|
}
|