Upgrade to Pro — share decks privately, control downloads, hide ads and more …

知っておくと便利なcurl

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for oohira oohira
July 23, 2015

 知っておくと便利なcurl

Avatar for oohira

oohira

July 23, 2015
Tweet

More Decks by oohira

Other Decks in Technology

Transcript

  1. $ curl ’http://httpbin.org/get?foo=bar&hoge=fuga' { "args": { "foo": "bar", "hoge": "fuga"

    }, "headers": { "Accept": "*/*", "Cache-Control": "max-age=259200", "Host": "httpbin.org", "User-Agent": "curl/7.37.1", "Via": "1.1 rt-in-osk:3128 (squid/2.6.STABLE21)" }, "origin": "113.37.30.210", "url": "http://httpbin.org/get?foo=bar&hoge=fuga" } リクエストパラメーターを指定
  2. $ curl -X POST --data 'foo=bar&hoge=fuga’ http://httpbin.org/post { "args": {},

    "data": "", "files": {}, "form": { "foo": "bar", "hoge": "fuga" }, "headers": { "Accept": "*/*", "Cache-Control": "max-age=259200", "Content-Length": "17", "Content-Type": "application/x-www-form-urlencoded", "Host": "httpbin.org", "User-Agent": "curl/7.37.1", "Via": "1.1 rt-in-osk:3128 (squid/2.6.STABLE21)" }, ... } POSTでフォーム送信
  3. $ curl -X POST -H 'Content-Type: application/json' --data '{"foo":"bar", "hoge":"fuga”}’

    http://httpbin.org/post { "args": {}, "data": "{\"foo\":\"bar\", \"hoge\":\"fuga\"}", "files": {}, "form": {}, "headers": { "Accept": "*/*", "Cache-Control": "max-age=259200", "Content-Length": "28", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "curl/7.37.1", "Via": "1.1 rt-in-osk:3128 (squid/2.6.STABLE21)" }, ... } POSTでJSON送信
  4. $ curl -X PUT -F 'file=@/path/to/file' http://httpbin.org/put { "args": {},

    "data": "", "files": { "file": "data:application/octet-stream;base64,iVBORw0KGgoAA... }, "form": {}, "headers": { "Accept": "*/*", "Cache-Control": "max-age=259200", "Content-Length": "8289", "Content-Type": "multipart/form-data; boundary=----------...", "Host": "httpbin.org", "User-Agent": "curl/7.37.1", "Via": "1.1 rt-in-osk:3128 (squid/2.6.STABLE21)" }, ... } PUTでファイル送信
  5. $ curl –i http://httpbin.org/redirect/1 HTTP/1.0 302 Moved Temporarily Server: nginx

    Date: Thu, 23 Jul 2015 01:55:25 GMT Content-Type: text/html; charset=utf-8 Content-Length: 215 Location: /get Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true X-Cache: MISS from rt-in-osk X-Cache-Lookup: MISS from rt-in-osk:3128 Via: 1.0 rt-in-osk:3128 (squid/2.6.STABLE21) Connection: close <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>Redirecting...</title> <h1>Redirecting...</h1> <p>You should be redirected automatically to target URL: <a href="/get">/get</a>. If not click the link. レスポンスヘッダを表示
  6. $ curl -o image.png http://httpbin.org/image/png % Total % Received %

    Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 8090 100 8090 0 0 38312 0 --:--:-- --:--:-- --:--:-- 38341 ファイルダウンロード $ curl http://httpbin.org/image/png > image.png % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 8090 100 8090 0 0 38312 0 --:--:-- --:--:-- --:--:-- 38341
  7. $ curl -H 'X-MyApp-API-Token: da39a3ee5e6b4b0d3255bf’ http://httpbin.org/headers { "headers": { "Accept":

    "*/*", "Cache-Control": "max-age=259200", "Host": "httpbin.org", "User-Agent": "curl/7.37.1", "Via": "1.1 rt-in-osk:3128 (squid/2.6.STABLE21)", "X-Myapp-Api-Token": "da39a3ee5e6b4b0d3255bf" } } カスタムヘッダを指定