CURL Command Line Keep Connection Open
Is there a way of getting curl (command line tool) to keep a http connection open? I am trying to test/debug a server application, which has a client that opens a http connection, makes a PUT request and leaves it open until some further action, and have been trying to use curl to simulate this.
However, according to the curl website:
The curl command-line tool can, however, only keep connections alive for as long as it runs, so as soon as it exits back to your command line it has to close down all currently open connections.
That much is fine, but is there a way of forcing it not to exit back to the command line (until I press any key or Ctrl-C or whatever it prefers), and therefore hold the connection open while I do the testing?
I have tried the "Connection: keep-alive"
header but this doesn't do the trick, the process still ends as soon as it's made the request, and the connection is closed.
If not, is there an alternative tool that can do this?
Answer
You can "trick" curl to keep the connection open. For example like this:
- Fire up
nc
to listen to a local port, say 8080 (nc -l -p 8080
on some versions of nc) - Run curl to get the resource you want, then add "localhost:8080" as a second URL on the same command line
This will make curl hold the first connection in its pool when it gets the second URL, and you make that second transfer just hang "indefinitely" which will make curl just leave the first connection open and alive until you control-c that or your nc process.
Related Questions
- → How to access the Visual interface for October?
- → How to implement DbDongle::convertTimestamps as workaround of invalid timestamps with MySql strict
- → Laravel 5: Apache php http authentication
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Disable CSRF TokenMismatch for specific routes on Lumen
- → Change fill color of d3.js node
- → Authenticate with a cookie using laravel 5.1 and jwt
- → What is causing the web page to reload?
- → Is there any way to make an SVG object clickable?
- → Keeping uploaded files secure but still available via https
- → CORS missmatch because of http
- → 500 Internal Server Error Ajax Laravel
- → React: How to publish page on server using React-starter-kit