{"id":15626,"date":"2021-02-11T09:00:27","date_gmt":"2021-02-11T08:00:27","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=15626"},"modified":"2021-02-11T09:00:27","modified_gmt":"2021-02-11T08:00:27","slug":"curl-fail-with-body","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2021\/02\/11\/curl-fail-with-body\/","title":{"rendered":"curl &#8211;fail-with-body"},"content":{"rendered":"\n<p>That&#8217;s <code>--fail-with-body<\/code>, using two dashes in front of the name.<\/p>\n\n\n\n<p>This is a brand new command line option added to curl, to appear in the 7.76.0 release. This function works like <code><a href=\"https:\/\/curl.se\/docs\/manpage.html#-f\">--fail<\/a><\/code> but with one little addition and I&#8217;m hoping the name should imply it good enough: <em>it also provides the response body.<\/em> The <code>--fail<\/code> option has turned out to be a surprisingly popular option but users have often repeated the request to also make it possible to get the body stored. <code>--fail<\/code> makes curl stop immediately after having received the response headers &#8211; if the response code says so.<\/p>\n\n\n\n<p><code>--fail-with-body<\/code> will instead first save the body per normal conventions and then return an error if the HTTP response code was 400 or larger.<\/p>\n\n\n\n<p>To be used like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl --fail-with-body -o output https:\/\/example.com\/404.html<\/pre>\n\n\n\n<p>If the page is missing on that HTTPS server, curl will return exit code 22 <strong>and<\/strong> save the error message response in the file named &#8216;output&#8217;.<\/p>\n\n\n\n<p>Not complicated at all. But has been requested many times!<\/p>\n\n\n\n<p>This is curl&#8217;s 238th command line option.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>That&#8217;s &#8211;fail-with-body, using two dashes in front of the name. This is a brand new command line option added to curl, to appear in the 7.76.0 release. This function works like &#8211;fail but with one little addition and I&#8217;m hoping the name should imply it good enough: it also provides the response body. The &#8211;fail &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2021\/02\/11\/curl-fail-with-body\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl &#8211;fail-with-body<\/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":[],"class_list":["post-15626","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-curl"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/15626","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=15626"}],"version-history":[{"count":6,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/15626\/revisions"}],"predecessor-version":[{"id":15768,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/15626\/revisions\/15768"}],"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=15626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=15626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=15626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}