-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost2server.py
35 lines (28 loc) · 1.03 KB
/
post2server.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
import requests
from log import logactivities
def send_json_to_endpoint(url, json_string, proxy_host="", proxy_port=""):
headers = {
"Content-Type": "application/json"
}
log = ""
try:
if proxy_host and proxy_port:
proxy_url = f"{proxy_host}:{proxy_port}"
proxies = {
"http": proxy_url,
"https": proxy_url
}
response = requests.post(
url, data=json_string, headers=headers, proxies=proxies)
else:
response = requests.post(url, data=json_string, headers=headers)
if response.status_code == 200:
log = "JSON string sent successfully!\n"
else:
log = f"Failed to send JSON string. Status code: {response.status_code}\n"
except requests.Timeout:
log = "Failed to send JSON string. Timeout\n"
except requests.RequestException as e:
log = f"An error occurred: {str(e)}\n"
# Append the log to the log file
logactivities(log,"monitor.log")