这段严格意义来说不能算是JavaScript,但是学习JavaScript总会写一点网络应用,所以也很简短很实用的记一下
注意了!实用!简短!只是HTTP的表象!我学过networking知道这玩意儿烦起来是多么可怕!protocol太复杂了!你以为是从A传到B,其实完全不是,是经过了整个英文字母表还循环了几遍才传到B的!
需要增添:我好像漏了TCP/IP,为啥呢……
/************************************* HTTP *********************************************/
//What's HTTP?
//1. it's the protocol used by the world wide web (you know, a bunch of interconnected documents, identified by URLs)
//2. it's a request-response protocol between a client and a server
//3. the client sends request, and the server sends back a response
//What does an actual HTTP request look like?
//1. a request line … a request method and a path
GET /teaching HTTP/1.1
//2. request headers (one per line)
Host: jvers.com, User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101
//3. an empty line
//4. an optional body
GET /~jversoza/ HTTP/1.1
Host:cs.nyu.edu
//What are some HTTP request methods?
GET //retrieves a resource (reads a resource)
POST //asks the server to store or update data (usually related to the resource itself) using the data supplied in the request body
PUT
DELETE
HEAD
//What does the response to a request look like?
//a status-line … which includes a status code and reason
HTTP/1.1 200 OK
//response header fields
Content-Type: text/html
//an empty line
//an optional message body - usually an HTML document!
HTTP/1.1 200 OK
Date: Tue, 29 Sep 2015 11:53:39 GMT
Server: Apache/2.2.15 (Red Hat)
...
(html document) ...
//What are the classes of response codes?
//1xx - informational
//2xx - success - 200 - OK
//3xx - redirect
//4xx - client error and don't do that again - 404 - Not Found
//5xx - server error and maybe try again later - 500 - Server Error
//What are the parts of a URL?
//1. scheme/protocol - http
//2. domain or actual ip address - pizzaforyou.com
//3. port (optional) - 80 (default if http)
//4. path - /search
//5. query_string (optional) - ?type=vegan
//6. fragment_id (optional) - #topresult
//scheme://domain:port/path?query_string#fragment_id
//https://pizzaforyou.com:80/search?type=vegan#top_result
//What are some tools that we use to make HTTP requests… and how do we use them?
//1. nc hostname port
//2. curl hostname
//3. Chrome!
//80 HTTP
//443 Https
//ports under 1000: privileged ports