Hypertext Transfer Protocol
1. Communication Process:
- Browser -> DNS Server -> (IP) Browser
- Browser -> (TCP/IP) Web Server [SYN connection] -> Browser [SYN-ACK connection] -> Web Server [ACK]
- Browser -> (HTTP request) Web Server -> (HTTP response) Browser
2. Ports:
- Telnet: 23
- SMTP: 25
- MySQL: 3306
For web servers:
- Deployment:
- HTTP: 80
- HTTPS: 443
- Development:
- HTTP: 8000 or 8080
- HTTPS: 8843
3. HTTP Request:
Methods:
- Safe:
- GET, HEAD, TRACE, OPTIONS
- Idempotent:
- PUT, DELETE (allowed to change the server, can have side effects, but multiple options should have the same effect as once)
- Update:
- POST (arbitrary changes)
HTTP Methods:
GET:
- To retrieve data. Can be cached. URL length is less than 2048 characters. Only ASCII.
- Example:
/test/demo_form.asp?name1=value1&name2=value2
POST:
- To post data. Cannot be cached. No length limitation. Supports all types (including binary).
- Example:
1
2
3POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
HEAD:
- Similar to GET, but only responds with the HTTP header, without the body.
PUT:
- Upload URI.
- Example: http://blog.csdn.net/yangruibao/article/details/7898788
DELETE:
- Delete resource.
OPTIONS:
- Response supported HTTP methods.
CONNECT:
- Changes connection to TCP/IP.
4. HTTP Response:
Response Headers:
Content-Type
,Content-Length
, etc.
Response Body:
- The content is a sequence of bytes with an associated MIME type.
Example:\r\n
(carriage return and newline).