forked from IBM/CodeEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-client.py
More file actions
30 lines (22 loc) · 711 Bytes
/
http-client.py
File metadata and controls
30 lines (22 loc) · 711 Bytes
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
import http.client, urllib.parse
import json
def main(params):
url = "httpbin.org"
connection = http.client.HTTPSConnection(url)
if params["__ce_method"] == "POST":
endpoint = "/post"
connection.request("POST", endpoint, json.dumps(params), {"Content-Type": "application/json"})
else:
endpoint = "/get"
connection.request("GET", endpoint)
response = connection.getresponse()
data = response.read()
connection.close()
dictData = json.loads(data)
return {
"headers": {
"Content-Type": "application/json",
},
"statusCode": response.status,
"body": dictData
}