Basic webserver supporting post+get (using curl and netcat)
0
votes
1
answer
740
views
Sorry if the question's title isn't clear about the objective of this question.
I was able to make a respond-only webserver using Bash only; when it gets a curl post request, it returns results no matter what the input.
## The post request
curl -d '{"Name":"Lorem", "age":"34"}' -H "Content-Type: application/json" -X POST http://:8080/
## The server's script (server.sh)
#!/bin/bash
while true; do
echo -e "HTTP/1.1 200 OK\n\nTitle
$(date)" \
| nc -l -k -p 8080 -q 1;
nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}';
done
In the first time I curl, it returns HTTP/1.1 200 OK\n\nTitle
$(date)
correctly, but not the nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}';
, and curl exits.
In the second time using curl, it doesn't return HTTP/1.1 200 OK\n\nTitle
$(date)
and now returns the result of nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}';
and curl doesn't exit.
The idea is to process the input from curl (using nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}';
+ jq
) but also to respond and then close curl/the connection.
Asked by Daniella Mesquita
(9 rep)
Mar 18, 2022, 06:20 PM
Last activity: Nov 20, 2024, 11:25 AM
Last activity: Nov 20, 2024, 11:25 AM