0

I want to submit some hundred HTTP requests using CURL, preferrably in parallel. This request simply shall submit a value to a server. How can I do this OS independent? I started writing a .txt file with a lot of lines looking like:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" url = http://localhost:8080/sales?salesAmount=111.91

Only the amount will vary.

Maybe better: The file contains only the amounts one in a line and the CURL command loops over the file and just reads each line as a parameter to be inserted into the CURL command!? Something like:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data "salesAmount={???} http://localhost:8080/sales

whereby {???} shall be filled with the value read from a .txt file.

1 Answer 1

0

currently curl does not support parallel transfers, but that will change in 6 days from now. on September 11 2019, curl version 7.66.0 will be released, which supports the brand new --parallel argument, for sending requests in parallel.

if you have curl version >= 7.66.0, you can do

curl --parallel $(cat list.txt)

if you don't, then you can use xargs to the same effect:

cat list.txt | xargs --max-procs=50 curl

as for portability, most modern unix systems (Linux/MacOS/*BSD/Illumos) ships cat and xargs by default, but Windows does not (but they can be installed on Windows via Cygwin or WSL )

4
  • Okay, thank you. It would be perfect if it could be done in parallel but it's not so important. But how can I do the rest of my question? How can I submit the request in some kind of loop with the arguments from the file: For instance, 100 values (lines) in the file with a float value in eacht line that should result in 100 request submissions whereby the value of each line should be inserted into the request as a salesAmount value (see above request).
    – du-it
    Sep 5, 2019 at 19:18
  • @du-it .. show an example of such a line with a float-whatever
    – hanshenrik
    Sep 5, 2019 at 19:58
  • See above in my question. Have a look at the URL (service). The parameter name is salesAmount and the value should be read from file. In the file each line just holds th evalue to be inserted. E.g. 127.75; next line 95.78; next line 1785.63 and so on.
    – du-it
    Sep 5, 2019 at 20:47
  • @du-it that's when you need a scripting language. php -r 'foreach(file("list.txt",FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES) as $amount){echo "--data salesAmount=".escapeshellarg($amount)."\n";}' | xargs --max-procs=50 curl -X POST -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/sales
    – hanshenrik
    Sep 5, 2019 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .