-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateSend.py
39 lines (30 loc) · 983 Bytes
/
UpdateSend.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
from flask import Flask, request, render_template
import json
import err
import DB
import urllib
import time
def do(path=[]) :
req = json.loads(request.form.get("data", "\"false\""))
if req == "false" :
return err.err("Err")
url = req['url'].split("?")[0] + "?"
postData = {}
for param in req['params'] :
if param['method'].lower() == "get" :
url += param['name'] + "=" + urllib.parse.quote_plus(param['value']) + "&"
else :
postData[param['name']] = param['value']
headers = {}
for header in req['headers'] :
headers[header['key']] = header['value']
startTime = time.time()
req = urllib.request.Request(url, data=urllib.parse.urlencode(postData).encode(), headers=headers)
read = urllib.request.urlopen(req).read()
try : read = read.decode("utf-8")
except : read
ret = {
"time": time.time() - startTime,
"html": read
}
return json.dumps(ret)