{"id":1847,"date":"2023-10-22T00:53:29","date_gmt":"2023-10-21T22:53:29","guid":{"rendered":"https:\/\/alessandromasciadri.com\/?p=1847"},"modified":"2023-10-22T00:54:07","modified_gmt":"2023-10-21T22:54:07","slug":"come-estrarre-http-status-code-e-content-di-una-chiamata-curl-con-bash","status":"publish","type":"post","link":"https:\/\/alessandromasciadri.com\/come-estrarre-http-status-code-e-content-di-una-chiamata-curl-con-bash\/","title":{"rendered":"Come estrarre HTTP status code e content di una chiamata Curl con Bash"},"content":{"rendered":"\t\t<div data-akihiro-type=\"ama-post\" data-akihiro-id=\"1847\" class=\"akihiro akihiro-1847\" data-akihiro-post-type=\"post\">\n\t\t\t\t<div class=\"akihiro-element akihiro-element-682c91e e-flex e-con-boxed e-con e-parent\" data-id=\"682c91e\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"akihiro-element akihiro-element-1847c70 akihiro-widget akihiro-widget-text-editor\" data-id=\"1847c70\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Nel seguente articolo vediamo come estrarre HTTP status code e content dalla response di una chiamata eseguita con Curl. Per fare ci\u00f2 ho preparato un semplice script bash.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-3e8cf43 akihiro-widget akihiro-widget-heading\" data-id=\"3e8cf43\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t<h3 class=\"akihiro-heading-title akihiro-size-default\">Estrarre HTTP status code e content dalla Curl response<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-a2a2f40 akihiro-widget akihiro-widget-text-editor\" data-id=\"a2a2f40\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Lo script \u00e8 talmente semplice che si commenta da solo.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-acd162f akihiro-widget akihiro-widget-code-highlight\" data-id=\"acd162f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>#!\/bin\/bash\n\nURL=\"https:\/\/www.alessandromasciadri.com\"\n\nresponse=$(curl -s -w \"%{http_code}\" $URL)\n\nhttp_code=$(tail -n1 <<< \"$response\")  # get the last line\ncontent=$(sed '$ d' <<< \"$response\")   # get all but the last line which contains the status code\n\necho \"$http_code\"\necho \"$content\"<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Nel seguente articolo vediamo come estrarre HTTP status code e content dalla response di una chiamata eseguita con Curl. Per fare ci\u00f2 ho preparato un semplice script bash. Estrarre HTTP status code e content dalla Curl response Lo script \u00e8 talmente semplice che si commenta da solo. #!\/bin\/bash URL=&#8221;https:\/\/www.alessandromasciadri.com&#8221; response=$(curl -s -w &#8220;%{http_code}&#8221; $URL) http_code=$(tail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[42,20],"class_list":["post-1847","post","type-post","status-publish","format-standard","hentry","category-programmazione","tag-bash","tag-linux"],"_links":{"self":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/1847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/comments?post=1847"}],"version-history":[{"count":4,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/1847\/revisions"}],"predecessor-version":[{"id":1851,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/1847\/revisions\/1851"}],"wp:attachment":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/media?parent=1847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/categories?post=1847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/tags?post=1847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}