8

If multiple URLs are passed to cURL, it reuses the TCP connection when possible.

For example:

curl -o 1.jpg http://example.com/1.jpg -o 2.jpg http://example.com/2.jpg

I need to do the same, but with different post queries to the same URL.

I thought maybe this would work:

curl -d "a=1" -o 1 http://example.com/script.php -d "a=2" -o 2 http://example.com/script.php

But instead of separating the -d arguments per request, it just adds them together.

Is there any way to achieve what I want with cURL?

If not, is there another tool which is likely to be present on a Linux system (e.g. Wget) which can do the above?

9

Since curl 7.36.0, the --next or -: command-line option allows delimiting URLs and their associated options. From the curl man page:

For example, you can do both a GET and a POST in a single command line:

curl www1.example.com --next -d postthis www2.example.com

Your desired request could be:

curl -d "a=1" -o 1 http://example.com/script.php --next -d "a=2" -o 2 http://example.com/script.php
1
3

The answer of Daniel Stenberg, the author of cURL:

We've previously discussed adding that ability but so far we haven't.

3
  • Why did you accept this answer, when it clearly doesn't actually answer the question? Also, where's the reference? – cnst Jan 11 '14 at 20:58
  • 1
    That's the answer: it's not possible. Added a reference. – Paul Jan 11 '14 at 21:01
  • 2
    It is now possible from curl 7.36.0. See my own separate answer. – Simon Pickup Jul 24 '19 at 16:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.