Automate Curl Multiple Http Requests

Automate Curl Multiple Http Requests

On Ubuntu server 16.04.6, I am using Curl (v. 7.47.0) to test my web-server and network components.

Using the -: option (also known as --next), I keep the TCP connection open, and send multiple HTTP requests to my server, for example:

 curl -s -o /dev/null  -: -s -d "data"  -: 

Now, assuming I would like to send exactly the same HTTP request 3 times, I would use:

curl -o /dev/null  -: -o /dev/null  -: -o /dev/null 

My question is: is there a way to repeat this HTTP request to the same uri with same options "n" amount of times without adding -: -o /dev/null over and over again?

For example, sending 100 of the same HTTP requests using the same TCP connection without writing -: -o /dev/null 99 times?

1 Answer

You can use xargs for this purpose like this:

for i in {1..100} ; do
  echo ' -o /dev/null  -:'
done | xargs curl -s

Please, note that xargs will not produce a command larger than 2,088,616 characters in my system. You can determine this maximum length in your system by running xargs --show-limits in your system.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.