Search code examples
httphttp-headershttprequestnetcat

How to send an incomplete http request using netcat?


I'd like to send a incomplete http request, or some kind of request that will temporarily block my server for a while. I wrote the server myself in C, and it is currently designed to only accept one client at a time. I want to test that this is indeed the case.

Would it be possible to send something simple, similar to GET /HTTP/1.0? I'm just doing all my testing in my terminal, not using anything else so far.


Solution

  • Yes, you can do this with netcat.

    nc -c servername 80 <<<"GET / HTTP/1.0"
    

    This will send the GET line and then wait for the server to respond. But the server should be waiting for headers and the blank line that ends them, so it will never respond. So nc will wait forever, keeping the connection open.