版权声明:本栏目下的所有文章均为个人学习笔记,部分内容为直接搬运,供学习分享。如有版权问题请联系作者删除。 https://blog.csdn.net/xiaozhenliu/article/details/83993679
HTTP & Web Servers
https://classroom.udacity.com/courses/ud303
Lesson 1: Requests & Responses
Introduction
Before started
- Terminal
- Python 3
- Git
- NMap Tools/ncat
URL
Here is an example of a URI: https://en.wikipedia.org/wiki/Fish
This URI has three visible parts, separated by a little bit of punctuation:
https
is the scheme;en.wikipedia.org
is the hostname;and /wiki/Fish
is the path.
Host names and Ports
host
or nslookup
Start the server
py -m http.server 8000
HTTP GET requests
Example: 127.0.0.1 - - [03/Oct/2016 15:45:50] "GET /readme.png HTTP/1.1" 200 -
- request line:
"GET /readme.png HTTP/1.1"
- method:
"GET"
- path:
"/readme.png"
- protocol:
"HTTP/1.1"
Exercise: Send a request by hand
ncat 127.0.0.1 8000
GET / HTTP/1.1
Host: localhost
Result:
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.7.1
Date: Mon, 12 Nov 2018 14:11:32 GMT
Content-type: text/html; charset=utf-8
Content-Length: 616
(The rest is HTML)
HTTP Responses
Status Line
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
- 1xx — Informational. The request is in progress or there’s another step to take.
- 2xx — Success! The request succeeded. The server is sending the data the client asked for.
- 3xx — Redirection. The server is telling the client a different URI it should redirect to. The headers will usually contain a Location header with the updated URI. Different codes tell the client whether a redirect is permanent or temporary.
- 4xx — Client error. The server didn’t understand the client’s request, or can’t or won’t fill it. Different codes tell the client whether it was a bad URI, a permissions problem, or another sort of error.
- 5xx — Server error. Something went wrong on the server side.