diff --git a/index.html b/index.html index d0660ed..ff4c823 100644 --- a/index.html +++ b/index.html @@ -31,6 +31,15 @@ float: left; width:33%; } + h1 { + margin-top: 0; + padding-top: .1em; + margin-bottom: .1em; + padding-bottom: .1em; + } + ul{ + margin-top: .2em; + }
@@ -39,7 +48,7 @@ class: center,middle # cURL ### [brettlangdon](http://brett.is) | [Shapeways](https://www.shapeways.com) - http://brettlangdon.github.io/curl-talk +http://brettlangdon.github.io/curl-talk --- @@ -54,8 +63,8 @@ Supported Protocols: * FTP * FTPS * GOPHER -* HTTP -* HTTPS] +* **HTTP** +* **HTTPS**] .float-block[ * IMAP * IMAPS @@ -100,14 +109,15 @@ Connection: close * `-h` - __Help:__ Show all CLI options * `-F CONTENT` - __Form Data:__ Add Multipart Form data to request * `-H HEADER` - __Header:__ Add HEADER to request header -* `-X COMMAND` - __Method:__ Which request method to use (GET/POST/etc) +* `-X COMMAND` - __Method:__ Set request method (GET/POST/etc) * `-o FILE` - __Output:__ Output to FILE rather than stdout * `-L` - __Follow Redirects:__ Follow all redirects +* `-i` - __Response Headers:__ Show the requests response headers --- # Download a File - +### Download to stdout ```bash $ curl http://www.google.com ... ``` -### Save to a File +### Save to a File "google-home.html" ```bash -$ curl -o google.com http://www.google.com +$ curl -o google-home.html http://www.google.com ``` --- # Response Headers Only - +* `-I` - Show response headers _ONLY_ ```bash $ curl -I http://www.google.com HTTP/1.1 200 OK @@ -133,8 +143,8 @@ Date: Sat, 26 Apr 2014 20:40:04 GMT Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 -Set-Cookie: PREF=ID=61629e9495553921:FF=0:TM=1398544804:LM=... -Set-Cookie: NID=67=HHSAgTCIZ3zd6w2hjrNqoX1VX9NDaqscV9YckpI2... +Set-Cookie: PREF=ID=61629e9495553921:FF=0:TM=1398544804... +Set-Cookie: NID=67=HHSAgTCIZ3zd6w2hjrNqoX1VX9NDaqscV9Yc... P3P: CP="This is not a P3P policy! See ..." Server: gws X-XSS-Protection: 1; mode=block @@ -146,9 +156,11 @@ Transfer-Encoding: chunked --- # Save/Reuse Cookies +* `-c FILE` - Save cookies to _FILE_ +* `-b FILE` - Load cookies from _FILE_ ```bash -$ curl -c cookies http://www.google.com +$ curl -c cookies -b cookies http://www.google.com $ cat cookies # Netscape HTTP Cookie File # http://curl.haxx.se/docs/http-cookies.html @@ -156,11 +168,111 @@ $ cat cookies ID=bec963a425f5d8ca:FF=0:TM=1398545024:LM=1398545024:S=... 67=BV0jhMokci-G3ZbOJ2UeFaNX1faFdfbFVcPHYIpAh35Uz2th6lVq... -# resuse stored cookies -$ curl -c cookies -b cookies http://www.google.com +``` + +--- + +# Following Redirects +* `-I` - Response headers only +* `-L` - Follow redirects + +```bash +$ curl -I -L http://google.com +HTTP/1.1 301 Moved Permanently +Location: http://www.google.com/ +... +Expires: Sat, 31 May 2014 12:50:05 GMT +Cache-Control: public, max-age=2592000 + +HTTP/1.1 200 OK +Date: Thu, 01 May 2014 12:50:05 GMT +Expires: -1 +Cache-Control: private, max-age=0 +Content-Type: text/html; charset=ISO-8859-1 +... +``` + +--- + +# HTTP POST Data +* `-X METHOD` - Set HTTP Request Method +* `-d DATA` - Send request form data + +```bash +$ curl -X POST -d "name=brett&talk=curl" http://httpbin.org/post +{ + "form": { + "name": "brett", + "talk": "curl" + }, + "headers": { + "Host": "httpbin.org", + "Content-Type": "application/x-www-form-urlencoded", + ... + }, + ... +} +``` + +--- + +# HTTP POST File +* `-d @FILE` - Send _FILE_ with the request +* `-X METHOD` - Set HTTP request method +* `-H HEADER` - Add _HEADER_ to request headers + +```bash +$ cat data.json +{"name": "brett","talk": "curl"} +$ curl -X POST -d @data.json \ + -H "Content-Type: application/json" http://httpbin.org/post +{ + "data": "{\"name\": \"brett\",\"talk\": \"curl\"}", + "json": { + "talk": "curl", + "name": "brett" + }, + "headers": { + "Content-Type": "application/json", + ... +} +``` + +--- + +# HTTPS + +```bash +$ curl https://www.google.com + +... +``` + +#### Allow Insecure Certs +* `-k` - Allow Insecure Certs + +```bash +$ curl -k https://insecure-site.gov +``` + +--- + +# Learning More +* cURL Website + * http://curl.haxx.se/ +* This talk + * http://brettlangdon.github.io/curl-talk +* httpbin (test http request/response) + * http://httpbin.org/ + +```bash +$ man curl +$ curl --help ``` - ",returnEnd:true,subLanguage:"javascript"}},{begin:"<%",end:"%>",subLanguage:"vbscript"},PHP,{className:"pi",begin:/<\?\w+/,end:/\?>/,relevance:10},{className:"tag",begin:"?",end:"/?>",contains:[{className:"title",begin:"[^ /><]+",relevance:0},TAG_INTERNALS]}]}}},{name:"css",create:function(hljs){var IDENT_RE="[a-zA-Z-][a-zA-Z0-9_-]*";var FUNCTION={className:"function",begin:IDENT_RE+"\\(",returnBegin:true,excludeEnd:true,end:"\\("};return{case_insensitive:true,illegal:"[=/|']",contains:[hljs.C_BLOCK_COMMENT_MODE,{className:"id",begin:"\\#[A-Za-z0-9_-]+"},{className:"class",begin:"\\.[A-Za-z0-9_-]+",relevance:0},{className:"attr_selector",begin:"\\[",end:"\\]",illegal:"$"},{className:"pseudo",begin:":(:)?[a-zA-Z0-9\\_\\-\\+\\(\\)\\\"\\']+"},{className:"at_rule",begin:"@(font-face|page)",lexemes:"[a-z-]+",keywords:"font-face page"},{className:"at_rule",begin:"@",end:"[{;]",contains:[{className:"keyword",begin:/\S+/},{begin:/\s/,endsWithParent:true,excludeEnd:true,relevance:0,contains:[FUNCTION,hljs.APOS_STRING_MODE,hljs.QUOTE_STRING_MODE,hljs.CSS_NUMBER_MODE]}]},{className:"tag",begin:IDENT_RE,relevance:0},{className:"rules",begin:"{",end:"}",illegal:"[^\\s]",relevance:0,contains:[hljs.C_BLOCK_COMMENT_MODE,{className:"rule",begin:"[^\\s]",returnBegin:true,end:";",endsWithParent:true,contains:[{className:"attribute",begin:"[A-Z\\_\\.\\-]+",end:":",excludeEnd:true,illegal:"[^\\s]",starts:{className:"value",endsWithParent:true,excludeEnd:true,contains:[FUNCTION,hljs.CSS_NUMBER_MODE,hljs.QUOTE_STRING_MODE,hljs.APOS_STRING_MODE,hljs.C_BLOCK_COMMENT_MODE,{className:"hexcolor",begin:"#[0-9A-Fa-f]+"},{className:"important",begin:"!important"}]}}]}]}]}}},{name:"scala",create:function(hljs){var ANNOTATION={className:"annotation",begin:"@[A-Za-z]+"};var STRING={className:"string",begin:'u?r?"""',end:'"""',relevance:10};var SYMBOL={className:"symbol",begin:"'\\w[\\w\\d_]*(?!')"};return{keywords:"type yield lazy override def with val var false true sealed abstract private trait "+"object null if for while throw finally protected extends import final return else "+"break new catch super class case package default try this match continue throws",contains:[{className:"javadoc",begin:"/\\*\\*",end:"\\*/",contains:[{className:"javadoctag",begin:"@[A-Za-z]+"}],relevance:10},hljs.C_LINE_COMMENT_MODE,hljs.C_BLOCK_COMMENT_MODE,STRING,hljs.QUOTE_STRING_MODE,SYMBOL,{className:"class",begin:"((case )?class |object |trait )",end:"({|$)",excludeEnd:true,illegal:":",keywords:"case class trait object",contains:[{beginKeywords:"extends with",relevance:10},hljs.UNDERSCORE_TITLE_MODE,{className:"params",begin:"\\(",end:"\\)",contains:[hljs.QUOTE_STRING_MODE,STRING,ANNOTATION]}]},hljs.C_NUMBER_MODE,ANNOTATION]}}},{name:"coffeescript",create:function(hljs){var KEYWORDS={keyword:"in if for while finally new do return else break catch instanceof throw try this "+"switch continue typeof delete debugger super "+"then unless until loop of by when and or is isnt not",literal:"true false null undefined "+"yes no on off",reserved:"case default function var void with const let enum export import native "+"__hasProp __extends __slice __bind __indexOf",built_in:"npm require console print module global window document"};var JS_IDENT_RE="[A-Za-z$_][0-9A-Za-z$_]*";var TITLE=hljs.inherit(hljs.TITLE_MODE,{begin:JS_IDENT_RE});var SUBST={className:"subst",begin:/#\{/,end:/}/,keywords:KEYWORDS};var EXPRESSIONS=[hljs.BINARY_NUMBER_MODE,hljs.inherit(hljs.C_NUMBER_MODE,{starts:{end:"(\\s*/)?",relevance:0}}),{className:"string",variants:[{begin:/'''/,end:/'''/,contains:[hljs.BACKSLASH_ESCAPE]},{begin:/'/,end:/'/,contains:[hljs.BACKSLASH_ESCAPE]},{begin:/"""/,end:/"""/,contains:[hljs.BACKSLASH_ESCAPE,SUBST]},{begin:/"/,end:/"/,contains:[hljs.BACKSLASH_ESCAPE,SUBST]}]},{className:"regexp",variants:[{begin:"///",end:"///",contains:[SUBST,hljs.HASH_COMMENT_MODE]},{begin:"//[gim]*",relevance:0},{begin:"/\\S(\\\\.|[^\\n])*?/[gim]*(?=\\s|\\W|$)"}]},{className:"property",begin:"@"+JS_IDENT_RE},{begin:"`",end:"`",excludeBegin:true,excludeEnd:true,subLanguage:"javascript"}];SUBST.contains=EXPRESSIONS;return{aliases:["coffee","cson","iced"],keywords:KEYWORDS,contains:EXPRESSIONS.concat([{className:"comment",begin:"###",end:"###"},hljs.HASH_COMMENT_MODE,{className:"function",begin:"("+JS_IDENT_RE+"\\s*=\\s*)?(\\(.*\\))?\\s*\\B[-=]>",end:"[-=]>",returnBegin:true,contains:[TITLE,{className:"params",begin:"\\(",returnBegin:true,contains:[{begin:/\(/,end:/\)/,keywords:KEYWORDS,contains:["self"].concat(EXPRESSIONS)}]}]},{className:"class",beginKeywords:"class",end:"$",illegal:/[:="\[\]]/,contains:[{beginKeywords:"extends",endsWithParent:true,illegal:/[:="\[\]]/,contains:[TITLE]},TITLE]},{className:"attribute",begin:JS_IDENT_RE+":",end:":",returnBegin:true,excludeEnd:true,relevance:0}])}}},{name:"lisp",create:function(hljs){var LISP_IDENT_RE="[a-zA-Z_\\-\\+\\*\\/\\<\\=\\>\\&\\#][a-zA-Z0-9_\\-\\+\\*\\/\\<\\=\\>\\&\\#!]*";var LISP_SIMPLE_NUMBER_RE="(\\-|\\+)?\\d+(\\.\\d+|\\/\\d+)?((d|e|f|l|s)(\\+|\\-)?\\d+)?";var SHEBANG={className:"shebang",begin:"^#!",end:"$"};var LITERAL={className:"literal",begin:"\\b(t{1}|nil)\\b"};var NUMBER={className:"number",variants:[{begin:LISP_SIMPLE_NUMBER_RE,relevance:0},{begin:"#b[0-1]+(/[0-1]+)?"},{begin:"#o[0-7]+(/[0-7]+)?"},{begin:"#x[0-9a-f]+(/[0-9a-f]+)?"},{begin:"#c\\("+LISP_SIMPLE_NUMBER_RE+" +"+LISP_SIMPLE_NUMBER_RE,end:"\\)"}]};var STRING=hljs.inherit(hljs.QUOTE_STRING_MODE,{illegal:null});var COMMENT={className:"comment",begin:";",end:"$"};var VARIABLE={className:"variable",begin:"\\*",end:"\\*"};var KEYWORD={className:"keyword",begin:"[:&]"+LISP_IDENT_RE};var QUOTED_LIST={begin:"\\(",end:"\\)",contains:["self",LITERAL,STRING,NUMBER]};var QUOTED={className:"quoted",contains:[NUMBER,STRING,VARIABLE,KEYWORD,QUOTED_LIST],variants:[{begin:"['`]\\(",end:"\\)"},{begin:"\\(quote ",end:"\\)",keywords:{title:"quote"}}]};var LIST={className:"list",begin:"\\(",end:"\\)"};var BODY={endsWithParent:true,relevance:0};LIST.contains=[{className:"title",begin:LISP_IDENT_RE},BODY];BODY.contains=[QUOTED,LIST,LITERAL,NUMBER,STRING,COMMENT,VARIABLE,KEYWORD];return{illegal:/\S/,contains:[NUMBER,SHEBANG,LITERAL,STRING,COMMENT,QUOTED,LIST]}}},{name:"clojure",create:function(hljs){var keywords={built_in:"def cond apply if-not if-let if not not= = < < > <= <= >= == + / * - rem "+"quot neg? pos? delay? symbol? keyword? true? false? integer? empty? coll? list? "+"set? ifn? fn? associative? sequential? sorted? counted? reversible? number? decimal? "+"class? distinct? isa? float? rational? reduced? ratio? odd? even? char? seq? vector? "+"string? map? nil? contains? zero? instance? not-every? not-any? libspec? -> ->> .. . "+"inc compare do dotimes mapcat take remove take-while drop letfn drop-last take-last "+"drop-while while intern condp case reduced cycle split-at split-with repeat replicate "+"iterate range merge zipmap declare line-seq sort comparator sort-by dorun doall nthnext "+"nthrest partition eval doseq await await-for let agent atom send send-off release-pending-sends "+"add-watch mapv filterv remove-watch agent-error restart-agent set-error-handler error-handler "+"set-error-mode! error-mode shutdown-agents quote var fn loop recur throw try monitor-enter "+"monitor-exit defmacro defn defn- macroexpand macroexpand-1 for dosync and or "+"when when-not when-let comp juxt partial sequence memoize constantly complement identity assert "+"peek pop doto proxy defstruct first rest cons defprotocol cast coll deftype defrecord last butlast "+"sigs reify second ffirst fnext nfirst nnext defmulti defmethod meta with-meta ns in-ns create-ns import "+"refer keys select-keys vals key val rseq name namespace promise into transient persistent! conj! "+"assoc! dissoc! pop! disj! use class type num float double short byte boolean bigint biginteger "+"bigdec print-method print-dup throw-if printf format load compile get-in update-in pr pr-on newline "+"flush read slurp read-line subvec with-open memfn time re-find re-groups rand-int rand mod locking "+"assert-valid-fdecl alias resolve ref deref refset swap! reset! set-validator! compare-and-set! alter-meta! "+"reset-meta! commute get-validator alter ref-set ref-history-count ref-min-history ref-max-history ensure sync io! "+"new next conj set! to-array future future-call into-array aset gen-class reduce map filter find empty "+"hash-map hash-set sorted-map sorted-map-by sorted-set sorted-set-by vec vector seq flatten reverse assoc dissoc list "+"disj get union difference intersection extend extend-type extend-protocol int nth delay count concat chunk chunk-buffer "+"chunk-append chunk-first chunk-rest max min dec unchecked-inc-int unchecked-inc unchecked-dec-inc unchecked-dec unchecked-negate "+"unchecked-add-int unchecked-add unchecked-subtract-int unchecked-subtract chunk-next chunk-cons chunked-seq? prn vary-meta "+"lazy-seq spread list* str find-keyword keyword symbol gensym force rationalize"};var CLJ_IDENT_RE="[a-zA-Z_0-9\\!\\.\\?\\-\\+\\*\\/\\<\\=\\>\\&\\#\\$';]+";var SIMPLE_NUMBER_RE="[\\s:\\(\\{]+\\d+(\\.\\d+)?";var NUMBER={className:"number",begin:SIMPLE_NUMBER_RE,relevance:0};var STRING=hljs.inherit(hljs.QUOTE_STRING_MODE,{illegal:null});var COMMENT={className:"comment",begin:";",end:"$",relevance:0};var COLLECTION={className:"collection",begin:"[\\[\\{]",end:"[\\]\\}]"};var HINT={className:"comment",begin:"\\^"+CLJ_IDENT_RE};var HINT_COL={className:"comment",begin:"\\^\\{",end:"\\}"};var KEY={className:"attribute",begin:"[:]"+CLJ_IDENT_RE};var LIST={className:"list",begin:"\\(",end:"\\)"};var BODY={endsWithParent:true,keywords:{literal:"true false nil"},relevance:0};var TITLE={keywords:keywords,lexemes:CLJ_IDENT_RE,className:"title",begin:CLJ_IDENT_RE,starts:BODY};LIST.contains=[{className:"comment",begin:"comment"},TITLE,BODY];BODY.contains=[LIST,STRING,HINT,HINT_COL,COMMENT,KEY,COLLECTION,NUMBER];COLLECTION.contains=[LIST,STRING,HINT,COMMENT,KEY,COLLECTION,NUMBER];return{aliases:["clj"],illegal:/\S/,contains:[COMMENT,LIST,{className:"prompt",begin:/^=> /,starts:{end:/\n\n|\Z/}}]}}},{name:"http",create:function(hljs){return{illegal:"\\S",contains:[{className:"status",begin:"^HTTP/[0-9\\.]+",end:"$",contains:[{className:"number",begin:"\\b\\d{3}\\b"}]},{className:"request",begin:"^[A-Z]+ (.*?) HTTP/[0-9\\.]+$",returnBegin:true,end:"$",contains:[{className:"string",begin:" ",end:" ",excludeBegin:true,excludeEnd:true}]},{className:"attribute",begin:"^\\w",end:": ",excludeEnd:true,illegal:"\\n|\\s|=",starts:{className:"string",end:"$"}},{begin:"\\n\\n",starts:{subLanguage:"",endsWithParent:true}}]}}},{name:"haskell",create:function(hljs){var COMMENT={className:"comment",variants:[{begin:"--",end:"$"},{begin:"{-",end:"-}",contains:["self"]}]};var PRAGMA={className:"pragma",begin:"{-#",end:"#-}"};var PREPROCESSOR={className:"preprocessor",begin:"^#",end:"$"};var CONSTRUCTOR={className:"type",begin:"\\b[A-Z][\\w']*",relevance:0};var LIST={className:"container",begin:"\\(",end:"\\)",illegal:'"',contains:[PRAGMA,COMMENT,PREPROCESSOR,{className:"type",begin:"\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?"},hljs.inherit(hljs.TITLE_MODE,{begin:"[_a-z][\\w']*"})]};var RECORD={className:"container",begin:"{",end:"}",contains:LIST.contains};return{aliases:["hs"],keywords:"let in if then else case of where do module import hiding "+"qualified type data newtype deriving class instance as default "+"infix infixl infixr foreign export ccall stdcall cplusplus "+"jvm dotnet safe unsafe family forall mdo proc rec",contains:[{className:"module",begin:"\\bmodule\\b",end:"where",keywords:"module where",contains:[LIST,COMMENT],illegal:"\\W\\.|;"},{className:"import",begin:"\\bimport\\b",end:"$",keywords:"import|0 qualified as hiding",contains:[LIST,COMMENT],illegal:"\\W\\.|;"},{className:"class",begin:"^(\\s*)?(class|instance)\\b",end:"where",keywords:"class family instance where",contains:[CONSTRUCTOR,LIST,COMMENT]},{className:"typedef",begin:"\\b(data|(new)?type)\\b",end:"$",keywords:"data family type newtype deriving",contains:[PRAGMA,COMMENT,CONSTRUCTOR,LIST,RECORD]},{className:"default",beginKeywords:"default",end:"$",contains:[CONSTRUCTOR,LIST,COMMENT]},{className:"infix",beginKeywords:"infix infixl infixr",end:"$",contains:[hljs.C_NUMBER_MODE,COMMENT]},{className:"foreign",begin:"\\bforeign\\b",end:"$",keywords:"foreign import export ccall stdcall cplusplus jvm "+"dotnet safe unsafe",contains:[CONSTRUCTOR,hljs.QUOTE_STRING_MODE,COMMENT]},{className:"shebang",begin:"#!\\/usr\\/bin\\/env runhaskell",end:"$"},PRAGMA,COMMENT,PREPROCESSOR,hljs.QUOTE_STRING_MODE,hljs.C_NUMBER_MODE,CONSTRUCTOR,hljs.inherit(hljs.TITLE_MODE,{begin:"^[_a-z][\\w']*"}),{begin:"->|<-"}]}}}];for(var i=0;i\s*<\/p>/g,"");highlightCodeBlocks(element,slideshow);return element}function styleContentElement(slideshow,element,properties){element.className="";setClassFromProperties(element,properties);setHighlightStyleFromProperties(element,properties,slideshow);setBackgroundFromProperties(element,properties)}function createNotesElement(slideshow,notes){var element=document.createElement("div");element.style.display="none";element.innerHTML=converter.convertMarkdown(notes);element.innerHTML=element.innerHTML.replace(/
\s*<\/p>/g,"");highlightCodeBlocks(element,slideshow);return element}function setBackgroundFromProperties(element,properties){var backgroundImage=properties["background-image"];if(backgroundImage){element.style.backgroundImage=backgroundImage}}function setHighlightStyleFromProperties(element,properties,slideshow){var highlightStyle=properties["highlight-style"]||slideshow.getHighlightStyle();if(highlightStyle){utils.addClass(element,"hljs-"+highlightStyle)}}function setClassFromProperties(element,properties){utils.addClass(element,"remark-slide-content");(properties["class"]||"").split(/,| /).filter(function(s){return s!==""}).forEach(function(c){utils.addClass(element,c)})}function highlightCodeBlocks(content,slideshow){var codeBlocks=content.getElementsByTagName("code");codeBlocks.forEach(function(block){if(block.parentElement.tagName!=="PRE"){return}if(block.className===""){block.className=slideshow.getHighlightLanguage()}if(block.className!==""){highlighter.engine.highlightBlock(block," ")}utils.addClass(block,"remark-code")})}},{"../converter":19,"../utils":11,"../highlighter":3}],18:[function(require,module,exports){module.exports=Lexer;var CODE=1,CONTENT=2,FENCES=3,SEPARATOR=4,NOTES_SEPARATOR=5;var regexByName={CODE:/(?:^|\n)( {4}[^\n]+\n*)+/,CONTENT:/(?:\\)?((?:\.[a-zA-Z_\-][a-zA-Z\-_0-9]*)+)\[/,FENCES:/(?:^|\n) *(`{3,}|~{3,}) *(?:\S+)? *\n(?:[\s\S]+?)\s*\3 *(?:\n+|$)/,SEPARATOR:/(?:^|\n)(---?)(?:\n|$)/,NOTES_SEPARATOR:/(?:^|\n)(\?{3})(?:\n|$)/};var block=replace(/CODE|CONTENT|FENCES|SEPARATOR|NOTES_SEPARATOR/,regexByName),inline=replace(/CODE|CONTENT|FENCES/,regexByName);function Lexer(){}Lexer.prototype.lex=function(src){var tokens=lex(src,block),i;for(i=tokens.length-2;i>=0;i--){if(tokens[i].type==="text"&&tokens[i+1].type==="text"){tokens[i].text+=tokens[i+1].text;tokens.splice(i+1,1)}}return tokens};function lex(src,regex,tokens){var cap,text;tokens=tokens||[];while((cap=regex.exec(src))!==null){if(cap.index>0){tokens.push({type:"text",text:src.substring(0,cap.index)})}if(cap[CODE]){tokens.push({type:"code",text:cap[0]})}else if(cap[FENCES]){tokens.push({type:"fences",text:cap[0]})}else if(cap[SEPARATOR]){tokens.push({type:"separator",text:cap[SEPARATOR]})}else if(cap[NOTES_SEPARATOR]){tokens.push({type:"notes_separator",text:cap[NOTES_SEPARATOR]})}else if(cap[CONTENT]){text=getTextInBrackets(src,cap.index+cap[0].length);if(text!==undefined){src=src.substring(text.length+1);tokens.push({type:"content_start",classes:cap[CONTENT].substring(1).split("."),block:text.indexOf("\n")!==-1});lex(text,inline,tokens);tokens.push({type:"content_end",block:text.indexOf("\n")!==-1})}else{tokens.push({type:"text",text:cap[0]})}}src=src.substring(cap.index+cap[0].length)}if(src||!src&&tokens.length===0){tokens.push({type:"text",text:src})}return tokens}function replace(regex,replacements){return new RegExp(regex.source.replace(/\w{2,}/g,function(key){return replacements[key].source}))}function getTextInBrackets(src,offset){var depth=1,pos=offset,chr;while(depth>0&&pos "+text+"
"}return'"+(escaped?code:escape(code,true))+"\n
\n"};Renderer.prototype.blockquote=function(quote){return"'+(escaped?code:escape(code,true))+"\n\n"+quote+"
\n"};Renderer.prototype.html=function(html){return html};Renderer.prototype.heading=function(text,level,raw){return"
\n":"
\n"};Renderer.prototype.list=function(body,ordered){var type=ordered?"ol":"ul";return"<"+type+">\n"+body+""+type+">\n"};Renderer.prototype.listitem=function(text){return"\n"+"\n"+header+"\n"+"\n"+body+"\n"+"
\n"};Renderer.prototype.tablerow=function(content){return"\n"+content+" \n"};Renderer.prototype.tablecell=function(content,flags){var type=flags.header?"th":"td";var tag=flags.align?"<"+type+' style="text-align:'+flags.align+'">':"<"+type+">";return tag+content+""+type+">\n"};Renderer.prototype.strong=function(text){return""+text+""};Renderer.prototype.em=function(text){return""+text+""};Renderer.prototype.codespan=function(text){return""+text+""};Renderer.prototype.br=function(){return this.options.xhtml?"
":"
"};Renderer.prototype.del=function(text){return""+text+""};Renderer.prototype.link=function(href,title,text){if(this.options.sanitize){try{var prot=decodeURIComponent(unescape(href)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(prot.indexOf("javascript:")===0){return""}}var out='"+text+"";return out};Renderer.prototype.image=function(href,title,text){var out='":">";return out};function Parser(options){this.tokens=[];this.token=null;this.options=options||marked.defaults;this.options.renderer=this.options.renderer||new Renderer;this.renderer=this.options.renderer;this.renderer.options=this.options}Parser.parse=function(src,options,renderer){var parser=new Parser(options,renderer);return parser.parse(src)};Parser.prototype.parse=function(src){this.inline=new InlineLexer(src.links,this.options,this.renderer);this.tokens=src.reverse();var out="";while(this.next()){out+=this.tok()}return out};Parser.prototype.next=function(){return this.token=this.tokens.pop()};Parser.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0};Parser.prototype.parseText=function(){var body=this.token.text;while(this.peek().type==="text"){body+="\n"+this.next().text}return this.inline.output(body)};Parser.prototype.tok=function(){switch(this.token.type){case"space":{return""}case"hr":{return this.renderer.hr()}case"heading":{return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text)}case"code":{return this.renderer.code(this.token.text,this.token.lang,this.token.escaped)}case"table":{var header="",body="",i,row,cell,flags,j;cell="";for(i=0;i
"+escape(e.message+"",true)+""}throw e}}marked.options=marked.setOptions=function(opt){merge(marked.defaults,opt);return marked};marked.defaults={gfm:true,tables:true,breaks:false,pedantic:false,sanitize:false,smartLists:false,silent:false,highlight:null,langPrefix:"lang-",smartypants:false,headerPrefix:"",renderer:new Renderer,xhtml:false};marked.Parser=Parser;marked.parser=Parser.parse;marked.Renderer=Renderer;marked.Lexer=Lexer;marked.lexer=Lexer.lex;marked.InlineLexer=InlineLexer;marked.inlineLexer=InlineLexer.output;marked.parse=marked;if(typeof exports==="object"){module.exports=marked}else if(typeof define==="function"&&define.amd){define(function(){return marked})}else{this.marked=marked}}.call(function(){return this||(typeof window!=="undefined"?window:global)}())}(window)},{}]},{},[1]); + diff --git a/slides.md b/slides.md new file mode 100644 index 0000000..8aa3852 --- /dev/null +++ b/slides.md @@ -0,0 +1,227 @@ +class: center,middle + +# cURL +### [brettlangdon](http://brett.is) | [Shapeways](https://www.shapeways.com) +http://brettlangdon.github.io/curl-talk + +--- + +# What is cURL? + +CLI tool for getting/sending files via URL's + +Supported Protocols: +.float-block[ +* DICT +* FILE +* FTP +* FTPS +* GOPHER +* **HTTP** +* **HTTPS**] +.float-block[ +* IMAP +* IMAPS +* LDAP +* LDAPS +* POP3 +* POP3S +* RTMP] +.float-block[ +* RTSP +* SCP +* SFTP +* SMTP +* SMTPS +* TELNET +* TFTP] + +--- + +# Quick Examples + +```bash +$ curl http://icanhazip.com +108.46.182.85 + +$ curl -i http://icanhazip.com +HTTP/1.1 200 OK +Date: Sat, 26 Apr 2014 19:49:57 GMT +Server: Apache +Content-Length: 14 +Content-Type: text/plain; charset=UTF-8 +Connection: close + +108.46.182.85 +``` + +--- + +# Useful CLI Arguments + +* `-v` - __Verbose:__ Make cURL more talkative +* `-h` - __Help:__ Show all CLI options +* `-F CONTENT` - __Form Data:__ Add Multipart Form data to request +* `-H HEADER` - __Header:__ Add HEADER to request header +* `-X COMMAND` - __Method:__ Set request method (GET/POST/etc) +* `-o FILE` - __Output:__ Output to FILE rather than stdout +* `-L` - __Follow Redirects:__ Follow all redirects +* `-i` - __Response Headers:__ Show the requests response headers + +--- + +# Download a File +### Download to stdout +```bash +$ curl http://www.google.com + +... +``` + +### Save to a File "google-home.html" + +```bash +$ curl -o google-home.html http://www.google.com +``` + +--- + +# Response Headers Only +* `-I` - Show response headers _ONLY_ +```bash +$ curl -I http://www.google.com +HTTP/1.1 200 OK +Date: Sat, 26 Apr 2014 20:40:04 GMT +Expires: -1 +Cache-Control: private, max-age=0 +Content-Type: text/html; charset=ISO-8859-1 +Set-Cookie: PREF=ID=61629e9495553921:FF=0:TM=1398544804... +Set-Cookie: NID=67=HHSAgTCIZ3zd6w2hjrNqoX1VX9NDaqscV9Yc... +P3P: CP="This is not a P3P policy! See ..." +Server: gws +X-XSS-Protection: 1; mode=block +X-Frame-Options: SAMEORIGIN +Alternate-Protocol: 80:quic +Transfer-Encoding: chunked +``` + +--- + +# Save/Reuse Cookies +* `-c FILE` - Save cookies to _FILE_ +* `-b FILE` - Load cookies from _FILE_ + +```bash +$ curl -c cookies -b cookies http://www.google.com +$ cat cookies +# Netscape HTTP Cookie File +# http://curl.haxx.se/docs/http-cookies.html +# This file was generated by libcurl! Edit at your own risk. + +ID=bec963a425f5d8ca:FF=0:TM=1398545024:LM=1398545024:S=... +67=BV0jhMokci-G3ZbOJ2UeFaNX1faFdfbFVcPHYIpAh35Uz2th6lVq... +``` + +--- + +# Following Redirects +* `-I` - Response headers only +* `-L` - Follow redirects + +```bash +$ curl -I -L http://google.com +HTTP/1.1 301 Moved Permanently +Location: http://www.google.com/ +... +Expires: Sat, 31 May 2014 12:50:05 GMT +Cache-Control: public, max-age=2592000 + +HTTP/1.1 200 OK +Date: Thu, 01 May 2014 12:50:05 GMT +Expires: -1 +Cache-Control: private, max-age=0 +Content-Type: text/html; charset=ISO-8859-1 +... +``` + +--- + +# HTTP POST Data +* `-X METHOD` - Set HTTP Request Method +* `-d DATA` - Send request form data + +```bash +$ curl -X POST -d "name=brett&talk=curl" http://httpbin.org/post +{ + "form": { + "name": "brett", + "talk": "curl" + }, + "headers": { + "Host": "httpbin.org", + "Content-Type": "application/x-www-form-urlencoded", + ... + }, + ... +} +``` + +--- + +# HTTP POST File +* `-d @FILE` - Send _FILE_ with the request +* `-X METHOD` - Set HTTP request method +* `-H HEADER` - Add _HEADER_ to request headers + +```bash +$ cat data.json +{"name": "brett","talk": "curl"} +$ curl -X POST -d @data.json \ + -H "Content-Type: application/json" http://httpbin.org/post +{ + "data": "{\"name\": \"brett\",\"talk\": \"curl\"}", + "json": { + "talk": "curl", + "name": "brett" + }, + "headers": { + "Content-Type": "application/json", + ... +} +``` + +--- + +# HTTPS + +```bash +$ curl https://www.google.com + +... +``` + +#### Allow Insecure Certs +* `-k` - Allow Insecure Certs + +```bash +$ curl -k https://insecure-site.gov +``` + +--- + +# Learning More +* cURL Website + * http://curl.haxx.se/ +* This talk + * http://brettlangdon.github.io/curl-talk +* httpbin (test http request/response) + * http://httpbin.org/ + +```bash +$ man curl +$ curl --help +```