Issue
Curl allows multiple GET requests to be made with a single command using {a,b}
as different variable inputs, e.g.
curl 'https://suggestqueries.google.com/complete/search?client={firefox,chrome}&q=potato&hl=en' -o '#1_tst'
Is there a way to do the same for POST requests? I've attempted
curl 'https://suggestqueries.google.com/complete/search' -X POST --data 'client={chrome,firefox}&q=potato&hl=en' -o '#1_tst'
which results in a single file named "#1_tst"
being written out. (This specific example request will fail no matter what, but l would like for two separate requests to be made).
Solution
You can use curl's --next
option for this.
Example:
curl --url 'https://suggestqueries.google.com/complete/search' \
--data 'client=chrome&q=potato&hl=en' -o 'chrome_tst' \
--next \
--url 'https://suggestqueries.google.com/complete/search' \
--data 'client=firefox&q=potato&hl=en' -o 'firefox_tst'
Alternatively, you can parametrize your command line in your shell and supply it via --config
:
curl --config <(for i in chrome firefox; do
printf '--url https://suggestqueries.google.com/complete/search\n';
printf '--data client='$i'&q=potato&hl=en\n-o '$i'_tst\n'; done)
Note that I have left out -X POST
because --data
already sets the right method:
Normally you do not need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated com‐ mand line options.
This option only changes the actual word used in the HTTP re‐ quest, it does not alter the way curl behaves. So for example if you want to make a proper HEAD request, using -X HEAD will not suffice. You need to use the --head option.
Answered By - maxschlepzig Answer Checked By - Senaida (WPSolving Volunteer)