-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_request.py
More file actions
42 lines (34 loc) · 1.19 KB
/
http_request.py
File metadata and controls
42 lines (34 loc) · 1.19 KB
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
import requests
# get
def get():
response = requests.get('http://localhost:8080/')
# check the response status code
if response.status_code == 200:
# if the response was successful, print the response text
print(response.text)
else:
# if the response was not successful, print an error message
print('An error occurred:', response.status_code)
# put
def put():
response = requests.put(url='http://localhost:8080/', data="hello put")
# check the response status code
if response.status_code == 200:
# if the response was successful, print the response text
print(response.text)
else:
# if the response was not successful, print an error message
print('An error occurred:', response.status_code)
# put
def post():
response = requests.put(url='http://localhost:8080/', data="hello post")
# check the response status code
if response.status_code == 200:
# if the response was successful, print the response text
print(response.text)
else:
# if the response was not successful, print an error message
print('An error occurred:', response.status_code)
get()
put()
post()