Search code examples
python-3.xnetcathttp-status-code-400

Use `nc` to create a http server that responds with a 400 and a json response message


I would like to create a simple server using nc or python -m SimpleHttpServer that would throw a 400 and send a JSON response which I could use to test error handling. I've tried httpbin.org/status/400 but that only comes back with a status code but no response.


Solution

  • Try this:

    while true; do { echo -e "HTTP/1.1 400 Bad Request\n\n{\"foo\": \"bar\"}"; } | nc -l 8080; done