{"id":1424,"date":"2011-11-07T09:28:30","date_gmt":"2011-11-07T09:28:30","guid":{"rendered":"http:\/\/thekua.com\/atwork\/?p=1424"},"modified":"2011-11-06T12:30:07","modified_gmt":"2011-11-06T12:30:07","slug":"scripting-web-applications-with-curl","status":"publish","type":"post","link":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/","title":{"rendered":"Scripting web applications with cURL"},"content":{"rendered":"<p>I first used <a href=\"http:\/\/curl.haxx.se\/\" title=\"cURL\">cURL<\/a> on a project a few years ago whilst testing a RESTful applciation. It&#8217;s a really great tool and plenty of options to do things. I however, keep forgetting some of the simple commands you might use to interact with a RESTful, or even just a web application. This is really good if you want to test AJAX resources as well. <\/p>\n<p>I&#8217;m putting the examples I&#8217;ve used the most up here for easy reference. You might even find it handy as well. <\/p>\n<p><strong>Perform a HTTP GET instead of POST<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">curl -G -F &quot;formParamName=@fileToSendOnDisk.txt&quot; http:\/\/localhost\/someGetUri<\/pre>\n<p><strong>Sending the contents of a file from disk as part of FORM data<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">curl -F &quot;formParamName=@fileToSendOnDisk.txt&quot; http:\/\/localhost\/someUri<\/pre>\n<p>Note that the @ is very important here. You can use curl to give it content type as well.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">curl -F &quot;formParamName=@fileToSendOnDisk.json;type=text\/json&quot; http:\/\/localhost\/someUri<\/pre>\n<p><strong>Sending form post data as a single string<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">curl -d &quot;param1=value1&amp;param2=value2&quot; http:\/\/localhost\/someUri<\/pre>\n<p><strong>Send some form post data and print the HTTP response code as the last row to the console<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">url -d &quot;param1=value1&amp;param2=value2&quot; http:\/\/localhost\/someUri -w &quot;%{http_code}\\n&quot;<\/pre>\n<p><strong>Post data to a HTTPs endpoint ignoring self-signed certificates<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">curl -d &quot;param1=value1&amp;param2=value2&quot; https:\/\/localhost\/someUri -k<\/pre>\n<p><strong>Follow redirects, printing out response code and URL that was last fetched after posting data<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">curl -d &quot;param1=value1&amp;param2=value2&quot; http:\/\/localhost\/someUri -k -w &quot;%{http_code}\\n%{url_effective}\\n&quot; -L<\/pre>\n<p>Hope you find this useful although you can find a much larger manual in the man page, or on <a href=\"http:\/\/curl.haxx.se\/docs\/manpage.html\" title=\"cURL manual\">this site here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I first used cURL on a project a few years ago whilst testing a RESTful applciation. It&#8217;s a really great tool and plenty of options to do things. I however, keep forgetting some of the simple commands you might use to interact with a RESTful, or even just a web application. This is really good [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7],"tags":[],"class_list":["post-1424","post","type-post","status-publish","format-standard","hentry","category-development","category-websites","post-preview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scripting web applications with cURL - patkua@work<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scripting web applications with cURL - patkua@work\" \/>\n<meta property=\"og:description\" content=\"I first used cURL on a project a few years ago whilst testing a RESTful applciation. It&#8217;s a really great tool and plenty of options to do things. I however, keep forgetting some of the simple commands you might use to interact with a RESTful, or even just a web application. This is really good [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/\" \/>\n<meta property=\"og:site_name\" content=\"patkua@work\" \/>\n<meta property=\"article:published_time\" content=\"2011-11-07T09:28:30+00:00\" \/>\n<meta name=\"author\" content=\"Patrick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@patkua\" \/>\n<meta name=\"twitter:site\" content=\"@patkua\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/\"},\"author\":{\"name\":\"Patrick\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"headline\":\"Scripting web applications with cURL\",\"datePublished\":\"2011-11-07T09:28:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/\"},\"wordCount\":317,\"commentCount\":2,\"articleSection\":[\"Development\",\"Websites\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/\",\"name\":\"Scripting web applications with cURL - patkua@work\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\"},\"datePublished\":\"2011-11-07T09:28:30+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2011\\\/11\\\/scripting-web-applications-with-curl\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scripting web applications with cURL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\",\"name\":\"patkua@work\",\"description\":\"The intersection of technology and leadership\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\",\"name\":\"Patrick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"caption\":\"Patrick\"},\"sameAs\":[\"http:\\\/\\\/thekua.com\\\/atwork\"],\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/author\\\/patrick\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scripting web applications with cURL - patkua@work","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/","og_locale":"en_US","og_type":"article","og_title":"Scripting web applications with cURL - patkua@work","og_description":"I first used cURL on a project a few years ago whilst testing a RESTful applciation. It&#8217;s a really great tool and plenty of options to do things. I however, keep forgetting some of the simple commands you might use to interact with a RESTful, or even just a web application. This is really good [&hellip;]","og_url":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/","og_site_name":"patkua@work","article_published_time":"2011-11-07T09:28:30+00:00","author":"Patrick","twitter_card":"summary_large_image","twitter_creator":"@patkua","twitter_site":"@patkua","twitter_misc":{"Written by":"Patrick","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/#article","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/"},"author":{"name":"Patrick","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"headline":"Scripting web applications with cURL","datePublished":"2011-11-07T09:28:30+00:00","mainEntityOfPage":{"@id":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/"},"wordCount":317,"commentCount":2,"articleSection":["Development","Websites"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/","url":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/","name":"Scripting web applications with cURL - patkua@work","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/#website"},"datePublished":"2011-11-07T09:28:30+00:00","author":{"@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"breadcrumb":{"@id":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thekua.com\/atwork\/2011\/11\/scripting-web-applications-with-curl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekua.com\/atwork\/"},{"@type":"ListItem","position":2,"name":"Scripting web applications with cURL"}]},{"@type":"WebSite","@id":"https:\/\/thekua.com\/atwork\/#website","url":"https:\/\/thekua.com\/atwork\/","name":"patkua@work","description":"The intersection of technology and leadership","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekua.com\/atwork\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae","name":"Patrick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","caption":"Patrick"},"sameAs":["http:\/\/thekua.com\/atwork"],"url":"https:\/\/thekua.com\/atwork\/author\/patrick\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/1424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/comments?post=1424"}],"version-history":[{"count":2,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/1424\/revisions"}],"predecessor-version":[{"id":1426,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/1424\/revisions\/1426"}],"wp:attachment":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/media?parent=1424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/categories?post=1424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/tags?post=1424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}