netcat-web-server/README.md
2024-12-06 22:14:39 -05:00

1.0 KiB

netcat Web Server

Serve a web page and inspect HTTP requests using netcat.

Usage

  1. After cloning the repository, make sure that the ncws.h script is executable.
$ chmod +x ncws.h
  1. Run the ncws.h script.
$ ./ncws.h
netcat web server
Listening on 0.0.0.0 8080
  1. In another terminal, make a request to the server using curl.
$ curl http://127.0.0.1:8080
  1. netcat will print the request and send a response.
...
Connection received on localhost 40790
GET / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/8.11.0
Accept: */*
  1. curl should receive the response and print it.
$ curl http://127.0.0.1:8080
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello, World!</title>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>
  1. The script will then resume listening for more requests.
...
Listening on 0.0.0.0 8080
  1. Press CTRL-C to terminate the script.