Skip to content

Instantly share code, notes, and snippets.

@U1F30C
Last active May 25, 2025 01:44
Show Gist options
  • Select an option

  • Save U1F30C/fd2dd70923685b6f47b4021e3611626b to your computer and use it in GitHub Desktop.

Select an option

Save U1F30C/fd2dd70923685b6f47b4021e3611626b to your computer and use it in GitHub Desktop.
Raw HTTP client and server over TCP with netcat

Using HTTP over raw TCP with netcat

Netcat HTTP

HTTP Client

Create a minimal raw HTTP request file request.txt. End of line must be CLRF.

GET / HTTP/1.1
Host: localhost
User-Agent: Netcat


This is the request body.

Use netcat to send the request over to the server

cat request.txt | nc 127.0.0.1 80

Optionally, pipe the output lynx to view the HTML response

cat request.txt | nc 127.0.0.1 80 | lynx

You can try this setup for any HTTP server, but many will require extra or specific headers to work propery. This was tested using NPM's htt-server package as a server.

HTTP Server

Use netcat to listen to TCP in specific port.

Create a response.txt file with the raw HTTP response

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Connection: close


<html>
  <head>
    <title>Response</title>
  </head>
  <body>
    <p>This is a reponse body</p>
  </body>
</html>
cat response.txt | netcat -l -p 8080

You can test by running your client command or direcly entering localhost:8080 on your browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment