-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-http-request.py
executable file
·56 lines (42 loc) · 1.48 KB
/
send-http-request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
import requests
def print_header(headline):
"""
print String into a # rectangle
:param headline: String witch should be include into a # boarder
"""
horizontal_line = ('{:#<{width}}'.format("", width='30'))
print(horizontal_line)
print('#{:^{width}}#'.format(headline, width='28'))
print(horizontal_line)
print()
def print_dict_as_table(dict, header_first="http header", header_second="value"):
"""
print a dict as a table
:param header_second: secound header text for the table
:param header_first: first header text for the table
:param dict: dict witch should be printed into a table
"""
horizontal_line = ('+{:-<32}+{:-<122}+'.format("", ""))
print(horizontal_line)
print('| {:<30} | {:<120} |'.format(header_first, header_second))
print(horizontal_line)
for key, value in dict.items():
print('| {:<30} | {:<120} |'.format(key, value))
print(horizontal_line)
print()
# print website url
print("Target Site: %s" % sys.argv[1])
if len(sys.argv) <= 2:
# do http request
current_request = requests.get(sys.argv[1])
else:
# do http request with custom header
headers = {sys.argv[2]: sys.argv[3]}
current_request = requests.get(sys.argv[1], headers=headers)
# print http request
print_header("http request content")
print_dict_as_table(current_request.request.headers)
# print http headers
print_header("http headers content")
print_dict_as_table(current_request.headers)