We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 547aa6a commit ff15681Copy full SHA for ff15681
2 files changed
…samples/function-http-python/__main__.py …ples/function-http-python/http-client.pyhelloworld-samples/function-http-python/__main__.py renamed to helloworld-samples/function-http-python/http-client.py
helloworld-samples/function-http-python/urlopen.py
@@ -0,0 +1,32 @@
1
+from urllib.request import urlopen, Request
2
+from urllib import parse
3
+import json
4
+
5
6
+def main(params):
7
8
+ url = "https://httpbin.org"
9
+ request = None
10
11
+ if params["__ce_method"] == "POST":
12
+ url = url + "/post"
13
+ data = json.dumps(params).encode()
14
+ request = Request(url, data=data, method='POST')
15
+ else:
16
+ url = url + "/get"
17
+ request = Request(url, method='GET')
18
19
20
+ request.add_header('Content-Type', 'application/json')
21
+ response = urlopen(request)
22
+ data = response.read()
23
24
+ dictData = json.loads(data)
25
26
+ return {
27
+ "headers": {
28
+ "Content-Type": "application/json",
29
+ },
30
+ "statusCode": response.status,
31
+ "body": dictData
32
+ }
0 commit comments