Стажировка 2016-07-12 02 Денис Нелюбин. web, http, tcp/ip
TRANSCRIPT
Internet и WebInternet• ARPANET• 1970-e — -1980-e• TCP/IP• E-mail, FTP, IRC…
Web (World Wide Web)• CERN (Tim Berners-Lee)• 1989• HTTP• HTML (hypertext)
Браузер1. Разобрать URL2. Отрезолвить имя сервера3. Отправить HTTP запрос4. Получить HTML5. Распарсить и отобразить HTML
URL и URIURL — Uniform Resource Locator — адреса в HTTP
URI — Uniform Resource Identifier — прочие идентификаторы в Internet
Domain Name Systemhttps://openclassrooms.com/courses/gerer-son-nom-de-domaine
Domain Name Systemhttps://openclassrooms.com/courses/gerer-son-nom-de-domaine
HTTPHyperText Transfer Protocol• Поверх TCP, порт 80• URL — адрес ресурса• Без сохранения состояния (stateless)• Текстовый
HTTPSHTTP Secure• Поверх TCP, порт 443• HTTP, зашифрованный TLS• Сертификат сервера• Сертификат клиента (не обязательно)
HTTP заголовки запросаHostUser-AgentAcceptCookieIf-Modified-SinceRange
AuthorizationRefererContent-TypeConnectionUpgrade
HTTP запросGET /wiki/страница HTTP/1.1Host: ru.wikipedia.orgUser-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5Accept: text/htmlConnection: close(пустая строка)
Коды состояния HTTPКод состояния = код ответа + поясняющая фраза200 OK303 See Other404 Not Found500 Internal Server Error
HTTP заголовки ответаServerDateCache-ControlExpiresLast-ModifiedLocation
Content-LengthСontent-TypeContent-DispositionContent-Range
HTTP ответHTTP/1.1 200 OKDate: Wed, 11 Feb 2009 11:20:59 GMTServer: ApacheX-Powered-By: PHP/5.2.4-2ubuntu5wm1Last-Modified: Wed, 11 Feb 2009 11:20:59 GMTContent-Language: ruContent-Type: text/html; charset=utf-8Content-Length: 1234Connection: close(пустая строка)
Инструменты разработчика % curl http://example.com -v* Rebuilt URL to: http://example.com/* Trying 93.184.216.34...* Connected to example.com (93.184.216.34) port 80 (#0)
> GET / HTTP/1.1...
Инструменты разработчикаhttps://www.getpostman.com/
• Apache Tomcat (Java)• Phusion Passenger (Ruby, Python, Node.
js)• Unicorn, thin (Ruby)• gUnicorn, uWSGI (Python)
Сервера приложений
HTTP клиент в JavaURL url = new URL("http://example.com");URLConnection connection = url.openConnection();try (InputStream in = connection.getInputStream()) { int b; while ((b = in.read()) >= 0) { System.out.write(b); }}