Skip to content

Instantly share code, notes, and snippets.

@catsoft
Last active September 9, 2016 19:53
Show Gist options
  • Save catsoft/baadd072f82cf77844179acd86de9b75 to your computer and use it in GitHub Desktop.
Save catsoft/baadd072f82cf77844179acd86de9b75 to your computer and use it in GitHub Desktop.

##Задание 1.2 ###Подключиться по telnet к http://wikipedia.org и отправить запрос. Проанализировать ответ сервера. Описать работу HTTP протокола

telnet wikipedia.org 80
Trying 91.198.174.192...
Connected to wikipedia.org.
Escape character is '^]'.
GET /wiki/страница HTTP/1.1
Host: ru.wikipedia.org
User-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509
Firefox/3.0b5
Accept: text/html
Connection: close
HTTP/1.1 301 TLS Redirect
Server: Varnish
Location: https://ru.wikipedia.org/wiki/страница
Content-Length: 0
Accept-Ranges: bytes
Date: Fri, 09 Sep 2016 11:16:18 GMT
X-Varnish: 2068448156
Age: 0
Via: 1.1 varnish
Connection: close
X-Cache: cp3031 int
X-Cache-Status: int
Set-Cookie: WMF-Last-Access=09-Sep-2016;Path=/;HttpOnly;secure;Expires=Tue, 11 Oct 2016 00:00:00 GMT
X-Client-IP: 212.193.76.52
Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
Set-Cookie: GeoIP=RU:SVE:Yekaterinburg:56.86:60.61:v4; Path=/; secure; Domain=.wikipedia.org

Connection closed by foreign host.

Установил соединение по 80 порту с wikipedia.org, отправил запрос на получение ресурса. В ответ получил код 301, который означает, что ресурс был перенесен на другой адрес, местоположение которого указано в заголовке 'Location'

##Задание 1.3 ###Отправить запросы на http://httpbin.org, проанализировать ответ и код состояния. Описать работу HTTP протокола в каждом запросе.

telnet  http://httpbin.org 80
Trying 54.175.219.8...
Connected to httpbin.org.
Escape character is '^]'.

Подключился к http://httpbin.org по 80 порту

GET /ip HTTP/1.1
Host: httpbin.org
Accept: */*
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 09 Sep 2016 12:01:30 GMT
Content-Type: application/json
Content-Length: 32
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "origin": "212.193.76.52"
}

Отправил Get запрос по адресу /ip. Получил код 200, который означает, что запрос выполнен успешно. В теле получил ip

GET /get?foo=bar&1=2&2/0&error=True HTTP/1.1
Host: httpbin.org
Accept: */*
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 09 Sep 2016 12:12:24 GMT
Content-Type: application/json
Content-Length: 254
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "args": {
    "1": "2", 
    "2/0": "", 
    "error": "True", 
    "foo": "bar"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.org"
  }, 
  "origin": "212.193.76.52", 
  "url": "http://httpbin.org/get?foo=bar&1=2&2%2F0&error=True"
}

Выполнил Get запрос с передачей параметров. Получил код 200 - успешно. В теле вернулись в формате json значения переменных, их заголовки и url

POST /post HTTP/1.1
Host: httpbin.org
Accept: */*
Content-Length: 35
Content-Type: application/x-www-form-urlencoded

foo=bar&1=2&2%2F0=&error=True
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 09 Sep 2016 12:09:02 GMT
Content-Type: application/json
Content-Length: 388
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "1": "2", 
    "2/0": "", 
    "error": "True\r\n\r\n\r\n", 
    "foo": "bar"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "35", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org"
  }, 
  "json": null, 
  "origin": "212.193.76.52", 
  "url": "http://httpbin.org/post"
}

Отправил post запрос с переменными. В ответ получил код 200 - успешно. В теле получил переменные, заголовки, ip клиента и url на который был отправлен запрос

GET /cookies/set?country=Ru HTTP/1.1
Host: httpbin.org
Accept: */*
HTTP/1.1 302 FOUND
Server: nginx
Date: Fri, 09 Sep 2016 12:20:13 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 223
Connection: keep-alive
Location: /cookies
Set-Cookie: country=Ru; Path=/
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/cookies">/cookies</a>.  If not click the link.

Отправил Get запрос на ресурс /cookies/set с указанием параметра Country и заголовков запроса. В ответ получил код 302, который означает что документ был найден, но в данный момент временно находится по другому адресу. Адрес можно увидеть в заголовке 'Location'

GET /cookies HTTP/1.1
Host: httpbin.org
Accept: */*
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 09 Sep 2016 12:25:38 GMT
Content-Type: application/json
Content-Length: 20
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "cookies": {}
}

Отправил get запрос по адресу /cookies. В ответ получил код 200. В теле получил параменр cookeis с пустым значением

GET /redirect/4 HTTP/1.1
Host: httpbin.org
Accept: */*
HTTP/1.1 302 FOUND
Server: nginx
Date: Fri, 09 Sep 2016 12:28:16 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 247
Connection: keep-alive
Location: /relative-redirect/3
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/relative-redirect/3">/relative-redirect/3</a>.  If not click the link.

Выполнил запрос по адресу /redirect/4. В ответ был получен код 302 - документ временно доступен по другому адресу, который указан в заголовке 'Location'

##Задание 1.3 ###Создать HTML форму c action=”http://httpbin.org/post” method=”POST” и enctype=”multipart/form-data”. Добавить в форму поля firstname, lastname, group, message (textarea), myimg (file). Проверить результат отправки данных формы. Проанализировать ответ. Описать работу HTTP протокола в данном случае.

Код страницы:

<!DOCTYPE HTML>
<html>
 <head>
  <title>Task 4</title>
 </head>
 <body>
 <form name="Task 1.4" method="POST" action="http://httpbin.org/post" enctype=”multipart/form-data”>
  <p>First Name:<br>
   <input type="text" name="firstname" size="50">
  </p>
  <p>Last Name:<br>
   <input type="text"  name="lastname" size="50">
  </p>
  <p>Group:<br>
   <input type="text"  name="group" size="50">
  </p>
  <p>Message:<br>
   <input type="textarea"  name="message" size="50">
  </p>
  <p>My image:<br>
   <input type="file" name="myimg" size="50">
  </p>

  <p><input type="submit" value="Send"></p>
 </form>
 </body>
</html>

Ответ:

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "firstname": "Alexandr", 
    "group": "fo-340001", 
    "lastname": "Vakhtin", 
    "message": "Hello World!", 
    "myimg": "picture.png"
  }, 
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "en-US,en;q=0.5", 
    "Content-Length": "92", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0"
  }, 
  "json": null, 
  "origin": "212.193.76.52", 
  "url": "http://httpbin.org/post"
}

Передаем методом пост передаем имя=значение, которые формируются из атрибута name и введеного значение. В ответе получили тоже самое только в формате json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment