{"id":13353,"date":"2020-03-02T11:30:31","date_gmt":"2020-03-02T10:30:31","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=13353"},"modified":"2020-03-13T10:10:48","modified_gmt":"2020-03-13T09:10:48","slug":"curl-ootw-next","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2020\/03\/02\/curl-ootw-next\/","title":{"rendered":"curl ootw: &#8211;next"},"content":{"rendered":"\n<p>(previously posted <a href=\"https:\/\/daniel.haxx.se\/blog\/2020\/01\/07\/curl-option-of-the-week\/\">options of the week<\/a>)<\/p>\n\n\n\n<p><code>--next<\/code> has the short option alternative <code>-:<\/code>. (Right, that&#8217;s dash colon as the short version!)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Working with multiple URLs<\/h2>\n\n\n\n<p>You can tell curl to send a string as a POST to a URL. And you can easily tell it to send that same data to three different URLs. Like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -d data URL1 URL2 URL2<\/pre>\n\n\n\n<p>&#8230; and you can easily ask curl to issue a HEAD request to two separate URLs, like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -I URL1 URL2<\/pre>\n\n\n\n<p>&#8230; and of course the easy, just GET four different URLs and send them all to stdout:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl URL1 URL2 URL3 URL4<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Doing many at once is beneficial<\/h2>\n\n\n\n<p>Of course you could also just invoke curl two, three or four times serially to accomplish the same thing. But if you do, you&#8217;d lose curl&#8217;s ability to use its DNS cache, its connection cache and TLS resumed sessions &#8211; as they&#8217;re all cached in memory. And if you wanted to use cookies from one transfer to the next, you&#8217;d have to store them on disk since curl can&#8217;t magically keep them in memory between separate command line invokes.<\/p>\n\n\n\n<p>Sometimes you want to use several URLs to make curl perform better.<\/p>\n\n\n\n<p>But what if you want to send different data in each of those three POSTs? Or what if you want to do both GET and POST requests in the same command line? <code>--next<\/code> is here for you!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>--next<\/code> is a separator!<\/h2>\n\n\n\n<p>Basically, <code>--next<\/code> resets the command line parser but lets curl keep all transfer related states and caches. I think it is easiest to explain with a set of examples.<\/p>\n\n\n\n<p>Send a POST followed by a GET:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -d data URL1 --next URL2<\/pre>\n\n\n\n<p>Send one string to URL1 and another string to URL2, both as POST:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -d one URL1 --next -d another URL2<\/pre>\n\n\n\n<p>Send a GET, activate cookies and do a HEAD that then sends back matching cookies.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -b empty URL1 --next -I URL1<\/pre>\n\n\n\n<p>First upload a file with PUT, then download it again<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -T file URL1 --next URL2<\/pre>\n\n\n\n<p>If you&#8217;re doing parallel transfers (with <code><a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-Z\">-Z<\/a><\/code>), curl will do URLs in parallel only until the <code>--next<\/code> separator.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">There&#8217;s no limit<\/h2>\n\n\n\n<p>As with most things curl, there&#8217;s no limit to the number of URLs you can specify on the command line and there&#8217;s no limit to the number of <code>--next<\/code> separators.<\/p>\n\n\n\n<p>If your command line isn&#8217;t long enough to hold them all, write them in a file and point them out to curl with <code><a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-K\">-K, --config<\/a><\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(previously posted options of the week) &#8211;next has the short option alternative -:. (Right, that&#8217;s dash colon as the short version!) Working with multiple URLs You can tell curl to send a string as a POST to a URL. And you can easily tell it to send that same data to three different URLs. Like &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2020\/03\/02\/curl-ootw-next\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl ootw: &#8211;next<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":13041,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[33,486],"class_list":["post-13353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-curl","tag-curl-and-libcurl","tag-option-of-the-week"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/13353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=13353"}],"version-history":[{"count":8,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/13353\/revisions"}],"predecessor-version":[{"id":13708,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/13353\/revisions\/13708"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media\/13041"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=13353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=13353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=13353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}