Last active
August 3, 2021 12:59
-
-
Save sashachabin/275193617955c191bb5d27fd3a6b31c0 to your computer and use it in GitHub Desktop.
УрФУ. Работа с протоколом HTTP через telnet, при помощи WebOb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Запрос к wikipedia.org | |
from webob import Request | |
request = Request.blank('/wiki/') | |
request.http_version = 'HTTP/1.1' | |
request.accept = 'text/html' | |
request.headers['Connection'] = 'Close' | |
request.host = 'ru.wikipedia.org' | |
request.user_agent = 'Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5' | |
# Сформированный запрос: | |
GET /wiki/ HTTP/1.1 | |
Accept: text/html | |
Connection: Close | |
Host: ru.wikipedia.org | |
User-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Задание 1 | |
from webob import Request | |
request = Request.blank('/ip') | |
request.http_version = 'HTTP/1.1' | |
request.host = 'httpbin.org' | |
request.accept = '*/*' | |
print(request) | |
# Сформированный запрос: | |
GET /ip HTTP/1.1 | |
Accept: */* | |
Host: httpbin.org | |
# Задание 2 | |
from webob import Request | |
request = Request.blank('/get?foo=bar&1=2&2/0&error=True') | |
request.http_version = 'HTTP/1.1' | |
request.host = 'httpbin.org' | |
request.accept = '*/*' | |
print(request) | |
# Сформированный запрос: | |
GET /get?foo=bar&1=2&2/0&error=True HTTP/1.1 | |
Accept: */* | |
Host: httpbin.org | |
# Задание 3 | |
from webob import Request | |
request = Request.blank('/post') | |
request.method = 'POST' | |
request.http_version = 'HTTP/1.1' | |
request.accept = '*/*' | |
request.text = 'foo=bar&1=2&2%2F0=&error=True' | |
#request.content_length = len(request.text) - вычисляется автоматически | |
request.content_type = 'application/x-www-form-urlencoded' | |
request.host = 'httpbin.org' | |
print(request) | |
# Сформированный запрос: | |
POST /post HTTP/1.1 | |
Accept: */* | |
Content-Length: 29 | |
Content-Type: application/x-www-form-urlencoded | |
Host: httpbin.org | |
foo=bar&1=2&2%2F0=&error=True | |
# Задание 4 | |
from webob import Request | |
request = Request.blank('/cookies/set?country=Ru') | |
request.http_version = 'HTTP/1.1' | |
request.accept = '*/*' | |
request.host = 'httpbin.org' | |
print(request) | |
# Сформированный запрос: | |
GET /cookies/set?country=Ru HTTP/1.1 | |
Accept: */* | |
Host: httpbin.org | |
# Задание 5 | |
from webob import Request | |
request = Request.blank('/cookies') | |
request.http_version = 'HTTP/1.1' | |
request.accept = '*/*' | |
request.host = 'httpbin.org' | |
print(request) | |
# Сформированный запрос: | |
GET /cookies HTTP/1.1 | |
Accept: */* | |
Host: httpbin.org | |
# Задание 6 | |
from webob import Request | |
request = Request.blank('/redirect/4') | |
request.http_version = 'HTTP/1.1' | |
request.accept = '*/*' | |
request.host = 'httpbin.org' | |
print(request) | |
# Сформированный запрос: | |
GET /redirect/4 HTTP/1.1 | |
Accept: */* | |
Host: httpbin.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Создание POST-запроса на http://httpbin.org/post | |
# с данными полей firstname, lastname, group, message, myimg | |
from webob import Request | |
request = Request.blank('/post') | |
request.method = 'POST' | |
request.http_version = 'HTTP/1.1' | |
request.accept = 'multipart/form-data' | |
request.host = 'httpbin.org' | |
# Тело запроса | |
request.text = 'firstname=Александр&lastname=Чабин&group=ФО-350005&message=text&myimg=' | |
print(request) | |
# Сформированный запрос: | |
POST /post HTTP/1.1 | |
Accept: multipart/form-data | |
Content-Length: 86 | |
Host: httpbin.org | |
firstname=Александр&lastname=Чабин&group=ФО-350005&message=text&myimg= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment