Integralist Integralist - 1 year ago 117
HTTP Question

simple single HTTP response using netcat as web server on macOS

I'm using macOS and have netcat installed via Homebrew

$ brew info netcat
netcat: stable 0.7.1 (bottled)
Utility for managing network connections
/usr/local/Cellar/netcat/0.7.1 (11 files, 104.2K) *
Poured from bottle on 2016-06-21 at 12:19:18

I'm just trying to get netcat to respond to an incoming curl request, but I think the problem I'm having is that netcat doesn't know when to respond.

Here is the content expected to be sent back, it's stored in

HTTP/1.1 200 OK

Here is the netcat command being run in one terminal shell:

sudo nc -l -p 80 < response.txt

Here is the curl command being run in another terminal shell:


Could someone help me understand what I would need to do in order to get this working as intended.

I can get this to work by using netcat instead of curl for the connection, but ideally I'd like a non-netcat client (such as curl or a web browser) to make a connection to localhost:80 and have the first instance of netcat respond.


Answer Source

Try using the macOS netcat instead of homebrew, and drop the -p option:

sudo /usr/bin/nc -l 80 < response.txt
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download