I'm using macOS and have netcat installed via Homebrew
$ brew info netcat
netcat: stable 0.7.1 (bottled)
Utility for managing network connections
http://netcat.sourceforge.net/
/usr/local/Cellar/netcat/0.7.1 (11 files, 104.2K) *
Poured from bottle on 2016-06-21 at 12:19:18
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/netcat.rb
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 response.txt:
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:
curl 127.0.0.1:80
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.
Thanks.
ncyou cannot use the-pflag together with the-lflag. That does not make sense and will throw an error. This is clearly explained in the man pages.sudo nc -l 80 < response.txt. Thecurlcommand receives and outputs the text stored in the fileresponse.txtsudo nc -l 80 < response.txtin one shell andcurl -v 127.0.0.1:80in another doesn't work for me. I getcurl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused