SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
cURL

                  ( )




2011-09-12(   )
curl
                    - transfer a URL
                  • curl is a tool to transfer data from
                    or to a server, using one of the
                    supported protocols (DICT, FILE,
                    FTP, FTPS, GOPHER, HTTP,
                    HTTPS, IMAP, IMAPS, LDAP,
                    LDAPS, POP3, POP3S, RTMP, RTSP,
                    SCP, SFTP, SMTP, SMTPS, TELNET
                    and TFTP).


2011-09-12(   )
why cURL is useful?




                  • curl -O http://example.com/
                   wallpapers/img[01-19].jpg

2011-09-12(   )
why cURL is useful
                  for Web Developers




2011-09-12(   )
HTTP

              $ telnet www.google.co.jp 80
              Trying 74.125.153.105...
              Connected to www.l.google.com.
              Escape character is '^]'.

              GET / HTTP/1.1
              Host: www.google.co.jp

              <   >


2011-09-12(   )
GET / HTTP/1.1


         [method] [request-uri] HTTP/1.1




2011-09-12(   )
2011-09-12(   )
Host: www.google.co.jp


                   Host: <   >




2011-09-12(   )
HTTP

              $ telnet www.google.co.jp 80
              Trying 74.125.153.105...
              Connected to www.l.google.com.
              Escape character is '^]'.

              GET / HTTP/1.1
              Host: www.google.co.jp

              <   >


2011-09-12(   )
curl
              $ curl -v http://www.google.co.jp
              * About to connect() to www.google.co.jp port 80
              (#0)
              *    Trying 74.125.153.106... connected*
              Connected to www.google.co.jp (74.125.153.106)
              port 80 (#0)
              > GET / HTTP/1.1
              > User-Agent: curl/7.21.7 ...
              > Host: www.google.co.jp
              > Accept: */*
              >
              < HTTP/1.1 200 OK
              < Date: Thu, 08 Sep 2011 06:47:44 GMT
              < Expires: -1
              < Cache-Control: private, max-age=0

2011-09-12(   )
curl --head
                     curl --verbose|-v

                  (curl --trace-ascii dump)



2011-09-12(   )
HTTP Header

              $ curl -v http://www.google.co.jp
              *   (ry)
              >   GET / HTTP/1.1
              >   User-Agent: curl/7.21.7 ...
              >   Host: www.google.co.jp
              >   Accept: */*
              >
              <   HTTP/1.1 200 OK
              <   Date: Thu, 08 Sep 2011 06:47:44 GMT
              <   Expires: -1
              <   Cache-Control: private, max-age=0




2011-09-12(   )
HTTP Request Headers
                  Accept

                  Accept-Language

                  Authorization

                  Host

                  Referer

                  User-Agent


2011-09-12(   )
$ curl -v -H 'Accept-Language: ja'
                 http://twitter.com |
                nokogrep -a content 'meta[name=description]'

              > GET / HTTP/1.1
              > User-Agent: curl/7.21.7
              > Host: twitter.com
              > Accept: */*
              > Accept-Language: ja
              >
              < HTTP/1.1 200 OK
              ...




2011-09-12(   )
$ curl -v -H 'Accept-Language: en'
                 http://twitter.com |
                nokogrep -a content 'meta[name=description]'

              > GET / HTTP/1.1
              > User-Agent: curl/7.21.7
              > Host: twitter.com
              > Accept: */*
              > Accept-Language: en
              >
              < HTTP/1.1 200 OK
              ...

              Instantly connect to what's most important to
              you. Follow your friends, experts, favorite
              celebrities, and breaking news.



2011-09-12(   )
$ curl -v 
                     -H 'Accept: application/json' 
                     http://jobs.dev/jobs | 
               ruby -rpp -rjson -e 'pp JSON.parse(STDIN.read)'

              >   GET /jobs HTTP/1.1
              >   User-Agent: curl/7.21.7
              >   Host: jobs.dev
              >   Accept: application/json




2011-09-12(   )
< HTTP/1.1 200 OK
              < Content-Type: application/json; charset=utf-8
              < X-UA-Compatible: IE=Edge
              < ETag: "1490b2d47b09a5abb92bd7eb09c4c51e"
              < Cache-Control:
                 max-age=0, private, must-revalidate
              < X-Runtime: 0.059816
              < Connection: keep-alive
              < Transfer-Encoding: chunked

              [{"created_at"=>"2011-09-07T05:56:22Z",
                "deadline"=>"2011-09-07",
                "description"=>"               !!!",
                  "id"=>1,
                  "public"=>true,
                  "title"=>"10         ",
                  "updated_at"=>"2011-09-07T09:59:33Z"}]


2011-09-12(   )
HTTP Response
              HTTP/1.1 200 OK
              Date: Mon, 12 Sep 2011 01:27:34 GMT
              Server: hi
              Status: 200 OK
              ETag: "ceedd0ac4f0339411aab820e225afcdf"
              Content-Type: text/html; charset=utf-8
              Content-Length: 44188
              Pragma: no-cache
              Expires: Tue, 31 Mar 1981 05:00:00 GMT
              Cache-Control: no-cache, no-store, must-
                 revalidate, pre-check=0, post-check=0
              X-XSS-Protection: 1; mode=block

2011-09-12(   )
HTTP Response
              HTTP/1.1 200 OK
              Date: Mon, 12 Sep 2011 01:27:34 GMT
              Server: hi
              Status: 200 OK
              ETag: "ceedd0ac4f0339411aab820e225afcdf"
              Content-Type: text/html; charset=utf-8
              Content-Length: 44188
              Pragma: no-cache
              Expires: Tue, 31 Mar 1981 05:00:00 GMT
              Cache-Control: no-cache, no-store, must-
                 revalidate, pre-check=0, post-check=0
              X-XSS-Protection: 1; mode=block

2011-09-12(   )
Status line
                  200

                  302

                  400

                  404

                  500

                  503


2011-09-12(   )
HTTP Status is app UI



                   200

                                   404 ?

                   410(Gone)


2011-09-12(   )
HTTP Response Headers
                   Location

                   Server



                   Content-Type

                   Content-Length



                   Expire, ETag, Cache-Control


2011-09-12(   )
curl --data|-d




2011-09-12(   )
POST via curl
      $ curl -v
             -d email=moro@example.jp 
             -d password=hogehoge 
             http://example.com/users

      POST /users HTTP/1.1
      User-Agent: curl/7.21.7
      Host: example.com
      Accept: */*
      Content-Length: 36
      Content-Type:
             application/x-www-form-urlencoded

2011-09-12(   )
HTTP/1.1 201 Created
  Content-Type: application/json
  Date: Mon, 12 Sep 2011 01:43:41 GMT
  Server: journey/0.4.0
  Content-Length: 71
  Connection: keep-alive

  {"email":"moro@example.jp","_id":"4e6d63cd981
  5710100000005","profiles":[]}



2011-09-12(   )
curl --user|-u




2011-09-12(   )
HTTP Authentication

      $ curl -v
             -u moro@example.jp:hogehoge 
             http://example.com/account

      GET /account HTTP/1.1
      Authorization:
          Basic bW9yb0BleGFtcGxlLmpwOmhvZ2Vob2dl
      User-Agent: curl/7.21.7
      Host: example.com
      Accept: */*



2011-09-12(   )
HTTP Authentication

      HTTP/1.1 200 OK
      Content-Type: application/json
      Date: Mon, 12 Sep 2011 01:51:00 GMT
      Server: journey/0.4.0
      Content-Length: 71
      Connection: keep-alive

      {"email":"moro@example.jp","_id":"4e6d63cd9
      815710100000005","profiles":[]}



2011-09-12(   )
cookie
                    &
                   cURL
                    http://flic.kr/p/5ekGdX
2011-09-12(   )
cookie

                  • HTTP              {Cookie}
                                  Web




                       http://www.studyinghttp.net/cookies
2011-09-12(   )
[res] Set-Cookie
                      [req] Cookie


                  • Netscape
                       Set-Cookie      Cookie          2
                    HTTP




                        http://www.studyinghttp.net/cookies#HeadersForCookie

2011-09-12(   )
2011-09-12(   )
2011-09-12(   )
curl --cookie|-b




2011-09-12(   )
without cookie


      $ curl -q http://jobs.dev |
        nokogrep '#header p.greeting'

                  Who are you?
                  Sign in




2011-09-12(   )
Cookie & cURL
      $ curl -v
             -b '_jobs_session=BAh7CEkiD3Nl(      )'
                    http://jobs.dev |
              nokogrep '#header p.greeting'

      GET / HTTP/1.1
      User-Agent: curl/7.21.7
      Host: jobs.dev
      Accept: */*
      Cookie: _jobs_session=BAh7CEkiD3Nl(     )


2011-09-12(   )
Cookie & cURL
      HTTP/1.1 200 OK
      Content-Type: text/html; charset=utf-8
      X-UA-Compatible: IE=Edge
      ETag: "8c0c63144925e4cc29b655906c221a3f"
      Set-Cookie:_jobs_session=BAh7CEkiD3Nl( )
      X-Runtime: 0.156343
      Connection: keep-alive
      Transfer-Encoding: chunked

                  Hi moro@example.jp
                  Sign out


2011-09-12(   )
2011-09-12(   )
$ curl -v 
                     -d 'user[email]=moro@example.jp'
                     -d 'user[password]=hogehoge'
                   http://jobs.dev/users/sign_in

              POST /users/sign_in HTTP/1.1
              User-Agent: curl/7.21.7
              Host: jobs.dev
              Accept: */*
              Content-Length: 51
              Content-Type:
                    application/x-www-form-urlencoded




2011-09-12(   )
HTTP/1.1 302 Moved Temporarily
              Location: http://jobs.dev/
              Content-Type: text/html; charset=utf-8
              X-UA-Compatible: IE=Edge
              Cache-Control: no-cache
              Set-Cookie: _jobs_session=BAh7CE( )
              X-Runtime: 0.217055
              Connection: keep-alive
              Transfer-Encoding: chunked

              <html><body>You are being <a
              href="http://jobs.dev/">redirected</
              a>.</body></html>




2011-09-12(   )
$ curl -v 
                     -b '_jobs_session=BAh7CE(    )'
                    http://jobs.dev/ |
                  nokogrep '#header p.greeting'

              GET / HTTP/1.1
              User-Agent: curl/7.21.7
              Host: jobs.dev
              Accept: */*
              Cookie: _jobs_session=BAh7CE(   )




2011-09-12(   )
HTTP/1.1 200 OK
              Content-Type: text/html; charset=utf-8
              X-UA-Compatible: IE=Edge
              ETag: "98d16875bdceb8c5451e7706e6071ece"
              Cache-Control:
                 max-age=0, private, must-revalidate
              Set-Cookie: _jobs_session=BAh7CUki( )
              X-Runtime: 0.193951
              Connection: keep-alive
              Transfer-Encoding: chunked

                      Hi moro@example.jp
                      Sign out


2011-09-12(   )
2011-09-12(   )
see also

                  • http://www.studyinghttp.net/
                  • http://www.studyinghttp.net/
                   rfc_ja/rfc2616
                  • http://amazon.jp/dp/
                   4774142042/morodiary05-22/
                   ref=nosim/



2011-09-12(   )

Contenu connexe

Tendances

Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
Elizabeth Smith
 
Realtime Communication Techniques with PHP
Realtime Communication Techniques with PHPRealtime Communication Techniques with PHP
Realtime Communication Techniques with PHP
WaterSpout
 
Scrip queue tree
Scrip queue treeScrip queue tree
Scrip queue tree
Marco Arias
 
Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites fly
Peter Keung
 

Tendances (20)

HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?
 
Efficient HTTP Apis
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP Apis
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
 
mod_perl 2.0 For Speed Freaks!
mod_perl 2.0 For Speed Freaks!mod_perl 2.0 For Speed Freaks!
mod_perl 2.0 For Speed Freaks!
 
HTTP Caching in Web Application
HTTP Caching in Web ApplicationHTTP Caching in Web Application
HTTP Caching in Web Application
 
Varnish Cache and Django (Falcon, Flask etc)
Varnish Cache and Django (Falcon, Flask etc)Varnish Cache and Django (Falcon, Flask etc)
Varnish Cache and Django (Falcon, Flask etc)
 
tdc2012
tdc2012tdc2012
tdc2012
 
I got 99 problems, but ReST ain't one
I got 99 problems, but ReST ain't oneI got 99 problems, but ReST ain't one
I got 99 problems, but ReST ain't one
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 
Ethernet Shield
Ethernet ShieldEthernet Shield
Ethernet Shield
 
Restfs internals
Restfs internalsRestfs internals
Restfs internals
 
Realtime Communication Techniques with PHP
Realtime Communication Techniques with PHPRealtime Communication Techniques with PHP
Realtime Communication Techniques with PHP
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 
Scrip queue tree
Scrip queue treeScrip queue tree
Scrip queue tree
 
Http capturing
Http capturingHttp capturing
Http capturing
 
Puppet
PuppetPuppet
Puppet
 
DEF CON 27- ALBINOWAX - http desync attacks
DEF CON 27- ALBINOWAX - http desync attacksDEF CON 27- ALBINOWAX - http desync attacks
DEF CON 27- ALBINOWAX - http desync attacks
 
Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites fly
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 

En vedette (6)

curl and new technologies
curl and new technologiescurl and new technologies
curl and new technologies
 
Internet all the things - curl everywhere!
Internet all the things - curl everywhere!Internet all the things - curl everywhere!
Internet all the things - curl everywhere!
 
HTTP/2 - for TCP/IP Geeks Stockholm
HTTP/2 - for TCP/IP Geeks StockholmHTTP/2 - for TCP/IP Geeks Stockholm
HTTP/2 - for TCP/IP Geeks Stockholm
 
Http2 right now
Http2 right nowHttp2 right now
Http2 right now
 
주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법
 
Docker Architecture (v1.3)
Docker Architecture (v1.3)Docker Architecture (v1.3)
Docker Architecture (v1.3)
 

Similaire à Introduction HTTP via cURL

REST Web Sebvice
REST Web SebviceREST Web Sebvice
REST Web Sebvice
khmerforge
 
Interactive web. O rly?
Interactive web. O rly?Interactive web. O rly?
Interactive web. O rly?
timbc
 

Similaire à Introduction HTTP via cURL (20)

HTTP
HTTPHTTP
HTTP
 
REST and JAX-RS
REST and JAX-RSREST and JAX-RS
REST and JAX-RS
 
Rpi python web
Rpi python webRpi python web
Rpi python web
 
Http2 kotlin
Http2   kotlinHttp2   kotlin
Http2 kotlin
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with selenium
 
Server architecture
Server architectureServer architecture
Server architecture
 
Ethernet Shield
Ethernet ShieldEthernet Shield
Ethernet Shield
 
Web tech 101
Web tech 101Web tech 101
Web tech 101
 
REST Web Sebvice
REST Web SebviceREST Web Sebvice
REST Web Sebvice
 
Cache is king
Cache is kingCache is king
Cache is king
 
Cache is the king
Cache is the kingCache is the king
Cache is the king
 
OWASP Top 10 - Checkmarx Presentation at Polytechnic Institute of Cávado and Ave
OWASP Top 10 - Checkmarx Presentation at Polytechnic Institute of Cávado and AveOWASP Top 10 - Checkmarx Presentation at Polytechnic Institute of Cávado and Ave
OWASP Top 10 - Checkmarx Presentation at Polytechnic Institute of Cávado and Ave
 
Web Application Security 101 - 02 The Basics
Web Application Security 101 - 02 The BasicsWeb Application Security 101 - 02 The Basics
Web Application Security 101 - 02 The Basics
 
Big Data & Cloud | Cloud Storage Simplified | Adrian Cole
Big Data & Cloud | Cloud Storage Simplified | Adrian ColeBig Data & Cloud | Cloud Storage Simplified | Adrian Cole
Big Data & Cloud | Cloud Storage Simplified | Adrian Cole
 
Interactive web. O rly?
Interactive web. O rly?Interactive web. O rly?
Interactive web. O rly?
 
Making the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsMaking the Most of HTTP In Your Apps
Making the Most of HTTP In Your Apps
 
Hidden Gems in HTTP
Hidden Gems in HTTPHidden Gems in HTTP
Hidden Gems in HTTP
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Devoxx Maroc 2015 HTTP 1, HTTP 2 and folks
Devoxx Maroc  2015 HTTP 1, HTTP 2 and folksDevoxx Maroc  2015 HTTP 1, HTTP 2 and folks
Devoxx Maroc 2015 HTTP 1, HTTP 2 and folks
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developers
 

Plus de Kyosuke MOROHASHI

Test Context Arrangement Recipebook
Test Context Arrangement RecipebookTest Context Arrangement Recipebook
Test Context Arrangement Recipebook
Kyosuke MOROHASHI
 

Plus de Kyosuke MOROHASHI (13)

Ruby ecosystem applied to agile project
Ruby ecosystem applied to agile projectRuby ecosystem applied to agile project
Ruby ecosystem applied to agile project
 
Test Context Arrangement Recipebook
Test Context Arrangement RecipebookTest Context Arrangement Recipebook
Test Context Arrangement Recipebook
 
Begin cucumber-in-real-world
Begin cucumber-in-real-worldBegin cucumber-in-real-world
Begin cucumber-in-real-world
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
Rails testing environment, 2009 fall
Rails testing environment, 2009 fallRails testing environment, 2009 fall
Rails testing environment, 2009 fall
 
TDD frameworks let me dream "Project Specific Language"
TDD frameworks let me dream "Project Specific Language"TDD frameworks let me dream "Project Specific Language"
TDD frameworks let me dream "Project Specific Language"
 
Rails Tokyo 035 Cucumber
Rails Tokyo 035 CucumberRails Tokyo 035 Cucumber
Rails Tokyo 035 Cucumber
 
OSC2008 勉強会大集合 Rails勉強会@東京
OSC2008 勉強会大集合 Rails勉強会@東京OSC2008 勉強会大集合 Rails勉強会@東京
OSC2008 勉強会大集合 Rails勉強会@東京
 
Capistrano in practice - WebCareer
Capistrano in practice - WebCareerCapistrano in practice - WebCareer
Capistrano in practice - WebCareer
 
named_scope more detail - WebCareer
named_scope more detail - WebCareernamed_scope more detail - WebCareer
named_scope more detail - WebCareer
 
named_scope more detail
named_scope more detailnamed_scope more detail
named_scope more detail
 
Rails <form> Chronicle
Rails <form> ChronicleRails <form> Chronicle
Rails <form> Chronicle
 
そうだ勉強会に行こう
そうだ勉強会に行こうそうだ勉強会に行こう
そうだ勉強会に行こう
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Introduction HTTP via cURL

  • 1. cURL ( ) 2011-09-12( )
  • 2. curl - transfer a URL • curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP). 2011-09-12( )
  • 3. why cURL is useful? • curl -O http://example.com/ wallpapers/img[01-19].jpg 2011-09-12( )
  • 4. why cURL is useful for Web Developers 2011-09-12( )
  • 5. HTTP $ telnet www.google.co.jp 80 Trying 74.125.153.105... Connected to www.l.google.com. Escape character is '^]'. GET / HTTP/1.1 Host: www.google.co.jp < > 2011-09-12( )
  • 6. GET / HTTP/1.1 [method] [request-uri] HTTP/1.1 2011-09-12( )
  • 8. Host: www.google.co.jp Host: < > 2011-09-12( )
  • 9. HTTP $ telnet www.google.co.jp 80 Trying 74.125.153.105... Connected to www.l.google.com. Escape character is '^]'. GET / HTTP/1.1 Host: www.google.co.jp < > 2011-09-12( )
  • 10. curl $ curl -v http://www.google.co.jp * About to connect() to www.google.co.jp port 80 (#0) * Trying 74.125.153.106... connected* Connected to www.google.co.jp (74.125.153.106) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.21.7 ... > Host: www.google.co.jp > Accept: */* > < HTTP/1.1 200 OK < Date: Thu, 08 Sep 2011 06:47:44 GMT < Expires: -1 < Cache-Control: private, max-age=0 2011-09-12( )
  • 11. curl --head curl --verbose|-v (curl --trace-ascii dump) 2011-09-12( )
  • 12. HTTP Header $ curl -v http://www.google.co.jp * (ry) > GET / HTTP/1.1 > User-Agent: curl/7.21.7 ... > Host: www.google.co.jp > Accept: */* > < HTTP/1.1 200 OK < Date: Thu, 08 Sep 2011 06:47:44 GMT < Expires: -1 < Cache-Control: private, max-age=0 2011-09-12( )
  • 13. HTTP Request Headers Accept Accept-Language Authorization Host Referer User-Agent 2011-09-12( )
  • 14. $ curl -v -H 'Accept-Language: ja' http://twitter.com | nokogrep -a content 'meta[name=description]' > GET / HTTP/1.1 > User-Agent: curl/7.21.7 > Host: twitter.com > Accept: */* > Accept-Language: ja > < HTTP/1.1 200 OK ... 2011-09-12( )
  • 15. $ curl -v -H 'Accept-Language: en' http://twitter.com | nokogrep -a content 'meta[name=description]' > GET / HTTP/1.1 > User-Agent: curl/7.21.7 > Host: twitter.com > Accept: */* > Accept-Language: en > < HTTP/1.1 200 OK ... Instantly connect to what's most important to you. Follow your friends, experts, favorite celebrities, and breaking news. 2011-09-12( )
  • 16. $ curl -v -H 'Accept: application/json' http://jobs.dev/jobs | ruby -rpp -rjson -e 'pp JSON.parse(STDIN.read)' > GET /jobs HTTP/1.1 > User-Agent: curl/7.21.7 > Host: jobs.dev > Accept: application/json 2011-09-12( )
  • 17. < HTTP/1.1 200 OK < Content-Type: application/json; charset=utf-8 < X-UA-Compatible: IE=Edge < ETag: "1490b2d47b09a5abb92bd7eb09c4c51e" < Cache-Control: max-age=0, private, must-revalidate < X-Runtime: 0.059816 < Connection: keep-alive < Transfer-Encoding: chunked [{"created_at"=>"2011-09-07T05:56:22Z", "deadline"=>"2011-09-07", "description"=>" !!!", "id"=>1, "public"=>true, "title"=>"10 ", "updated_at"=>"2011-09-07T09:59:33Z"}] 2011-09-12( )
  • 18. HTTP Response HTTP/1.1 200 OK Date: Mon, 12 Sep 2011 01:27:34 GMT Server: hi Status: 200 OK ETag: "ceedd0ac4f0339411aab820e225afcdf" Content-Type: text/html; charset=utf-8 Content-Length: 44188 Pragma: no-cache Expires: Tue, 31 Mar 1981 05:00:00 GMT Cache-Control: no-cache, no-store, must- revalidate, pre-check=0, post-check=0 X-XSS-Protection: 1; mode=block 2011-09-12( )
  • 19. HTTP Response HTTP/1.1 200 OK Date: Mon, 12 Sep 2011 01:27:34 GMT Server: hi Status: 200 OK ETag: "ceedd0ac4f0339411aab820e225afcdf" Content-Type: text/html; charset=utf-8 Content-Length: 44188 Pragma: no-cache Expires: Tue, 31 Mar 1981 05:00:00 GMT Cache-Control: no-cache, no-store, must- revalidate, pre-check=0, post-check=0 X-XSS-Protection: 1; mode=block 2011-09-12( )
  • 20. Status line 200 302 400 404 500 503 2011-09-12( )
  • 21. HTTP Status is app UI 200 404 ? 410(Gone) 2011-09-12( )
  • 22. HTTP Response Headers Location Server Content-Type Content-Length Expire, ETag, Cache-Control 2011-09-12( )
  • 24. POST via curl $ curl -v -d email=moro@example.jp -d password=hogehoge http://example.com/users POST /users HTTP/1.1 User-Agent: curl/7.21.7 Host: example.com Accept: */* Content-Length: 36 Content-Type: application/x-www-form-urlencoded 2011-09-12( )
  • 25. HTTP/1.1 201 Created Content-Type: application/json Date: Mon, 12 Sep 2011 01:43:41 GMT Server: journey/0.4.0 Content-Length: 71 Connection: keep-alive {"email":"moro@example.jp","_id":"4e6d63cd981 5710100000005","profiles":[]} 2011-09-12( )
  • 27. HTTP Authentication $ curl -v -u moro@example.jp:hogehoge http://example.com/account GET /account HTTP/1.1 Authorization: Basic bW9yb0BleGFtcGxlLmpwOmhvZ2Vob2dl User-Agent: curl/7.21.7 Host: example.com Accept: */* 2011-09-12( )
  • 28. HTTP Authentication HTTP/1.1 200 OK Content-Type: application/json Date: Mon, 12 Sep 2011 01:51:00 GMT Server: journey/0.4.0 Content-Length: 71 Connection: keep-alive {"email":"moro@example.jp","_id":"4e6d63cd9 815710100000005","profiles":[]} 2011-09-12( )
  • 29. cookie & cURL http://flic.kr/p/5ekGdX 2011-09-12( )
  • 30. cookie • HTTP {Cookie} Web http://www.studyinghttp.net/cookies 2011-09-12( )
  • 31. [res] Set-Cookie [req] Cookie • Netscape Set-Cookie Cookie 2 HTTP http://www.studyinghttp.net/cookies#HeadersForCookie 2011-09-12( )
  • 35. without cookie $ curl -q http://jobs.dev | nokogrep '#header p.greeting' Who are you? Sign in 2011-09-12( )
  • 36. Cookie & cURL $ curl -v -b '_jobs_session=BAh7CEkiD3Nl( )' http://jobs.dev | nokogrep '#header p.greeting' GET / HTTP/1.1 User-Agent: curl/7.21.7 Host: jobs.dev Accept: */* Cookie: _jobs_session=BAh7CEkiD3Nl( ) 2011-09-12( )
  • 37. Cookie & cURL HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 X-UA-Compatible: IE=Edge ETag: "8c0c63144925e4cc29b655906c221a3f" Set-Cookie:_jobs_session=BAh7CEkiD3Nl( ) X-Runtime: 0.156343 Connection: keep-alive Transfer-Encoding: chunked Hi moro@example.jp Sign out 2011-09-12( )
  • 39. $ curl -v -d 'user[email]=moro@example.jp' -d 'user[password]=hogehoge' http://jobs.dev/users/sign_in POST /users/sign_in HTTP/1.1 User-Agent: curl/7.21.7 Host: jobs.dev Accept: */* Content-Length: 51 Content-Type: application/x-www-form-urlencoded 2011-09-12( )
  • 40. HTTP/1.1 302 Moved Temporarily Location: http://jobs.dev/ Content-Type: text/html; charset=utf-8 X-UA-Compatible: IE=Edge Cache-Control: no-cache Set-Cookie: _jobs_session=BAh7CE( ) X-Runtime: 0.217055 Connection: keep-alive Transfer-Encoding: chunked <html><body>You are being <a href="http://jobs.dev/">redirected</ a>.</body></html> 2011-09-12( )
  • 41. $ curl -v -b '_jobs_session=BAh7CE( )' http://jobs.dev/ | nokogrep '#header p.greeting' GET / HTTP/1.1 User-Agent: curl/7.21.7 Host: jobs.dev Accept: */* Cookie: _jobs_session=BAh7CE( ) 2011-09-12( )
  • 42. HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 X-UA-Compatible: IE=Edge ETag: "98d16875bdceb8c5451e7706e6071ece" Cache-Control: max-age=0, private, must-revalidate Set-Cookie: _jobs_session=BAh7CUki( ) X-Runtime: 0.193951 Connection: keep-alive Transfer-Encoding: chunked Hi moro@example.jp Sign out 2011-09-12( )
  • 44. see also • http://www.studyinghttp.net/ • http://www.studyinghttp.net/ rfc_ja/rfc2616 • http://amazon.jp/dp/ 4774142042/morodiary05-22/ ref=nosim/ 2011-09-12( )