-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_test.py
More file actions
32 lines (26 loc) · 1 KB
/
Copy pathpy_test.py
File metadata and controls
32 lines (26 loc) · 1 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
import requests
import sys
def test_web_server(url):
try:
# Send a GET request to the specified URL
response = requests.get(url)
# Send a POST request to the specified URL
# myobj = {'somekey': 'somevalue'}
# response = requests.post(url, json = myobj)
# Print the status code of the response
print(f"Status Code: {response.status_code}")
# Print the content of the response
print("Response Content:")
print(response.text)
except requests.exceptions.RequestException as e:
# Print any error that occurs during the request
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Check if a URL is provided as a command-line argument
if len(sys.argv) != 2:
print("Usage: python3 py_test.py <url, e.g. http://localhost:8080/>")
sys.exit(1)
# Get the URL from the command-line argument
url_to_test = sys.argv[1]
# Test the web server response
test_web_server(url_to_test)