diff --git a/examples/requests/post_data.py b/examples/requests/post_data.py index 4792e56a1..84d9c1ae4 100644 --- a/examples/requests/post_data.py +++ b/examples/requests/post_data.py @@ -3,8 +3,12 @@ header = {"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryrEPACvZYkAbE4bYB"} -a = requests.request("POST", "http://pikascript.com/upload", headers=header, data=form_data) +a = requests.request("POST", "http://httpbin.org/post", + headers=header, data=form_data) + +# a = requests.request("POST", "http://pikascript.com/uploads", +# headers=header, data=form_data) print(a.headers) print(a.content_length) -print(a.text) \ No newline at end of file +print(a.text) diff --git a/package/requests/requests.py b/package/requests/requests.py index 490ac5080..9056c9e5b 100644 --- a/package/requests/requests.py +++ b/package/requests/requests.py @@ -56,10 +56,10 @@ def request( files=None, json=None, data=None) -> Response: - if files != None: + if files is not None: print("files is not supported") return None - if json != None: + if json is not None: print("json is not supported") return None """ @@ -69,25 +69,41 @@ def request( rqst.url = url # 初始化,分配内存, 写入方法POST/GET ret = rqst.request_init(method) + # print("Request init ret: " + str(ret)) if ret != 1: + print("Failed to initialize the request object.") return None + # 写入URL ret = _append_params_to_url(rqst, url, params) - if ret != 1: + # print("Append params to URL ret: " + str(ret)) + if ret != 1: # 出现错误,需要释放对象 + print("Error appending params to the URL.") return None + # 写入默认HTTP版本号 ret = rqst.proto_write('') + # print("Write HTTP version ret: " + str(ret)) if ret != 1: + print("Error writing HTTP version.") return None + # 写入响应头数据 ret = _append_headers(rqst, headers) + # print("Append headers ret: " + str(ret)) if ret != 1: + print("Error appending headers to the request.") return None + ret = rqst.request(method, rqst.url, timeout, data) + # print("Request ret: " + str(ret)) if ret != 1: + print("Request failed with response code: " + str(ret)) return None + return rqst + def get(url: str, params=None) -> Response: return request('GET', url, params) diff --git a/port/linux/package/pikascript/requests.py b/port/linux/package/pikascript/requests.py index 490ac5080..9056c9e5b 100644 --- a/port/linux/package/pikascript/requests.py +++ b/port/linux/package/pikascript/requests.py @@ -56,10 +56,10 @@ def request( files=None, json=None, data=None) -> Response: - if files != None: + if files is not None: print("files is not supported") return None - if json != None: + if json is not None: print("json is not supported") return None """ @@ -69,25 +69,41 @@ def request( rqst.url = url # 初始化,分配内存, 写入方法POST/GET ret = rqst.request_init(method) + # print("Request init ret: " + str(ret)) if ret != 1: + print("Failed to initialize the request object.") return None + # 写入URL ret = _append_params_to_url(rqst, url, params) - if ret != 1: + # print("Append params to URL ret: " + str(ret)) + if ret != 1: # 出现错误,需要释放对象 + print("Error appending params to the URL.") return None + # 写入默认HTTP版本号 ret = rqst.proto_write('') + # print("Write HTTP version ret: " + str(ret)) if ret != 1: + print("Error writing HTTP version.") return None + # 写入响应头数据 ret = _append_headers(rqst, headers) + # print("Append headers ret: " + str(ret)) if ret != 1: + print("Error appending headers to the request.") return None + ret = rqst.request(method, rqst.url, timeout, data) + # print("Request ret: " + str(ret)) if ret != 1: + print("Request failed with response code: " + str(ret)) return None + return rqst + def get(url: str, params=None) -> Response: return request('GET', url, params) diff --git a/port/linux/test/python/requests/post_data.py b/port/linux/test/python/requests/post_data.py index 4792e56a1..84d9c1ae4 100644 --- a/port/linux/test/python/requests/post_data.py +++ b/port/linux/test/python/requests/post_data.py @@ -3,8 +3,12 @@ header = {"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryrEPACvZYkAbE4bYB"} -a = requests.request("POST", "http://pikascript.com/upload", headers=header, data=form_data) +a = requests.request("POST", "http://httpbin.org/post", + headers=header, data=form_data) + +# a = requests.request("POST", "http://pikascript.com/uploads", +# headers=header, data=form_data) print(a.headers) print(a.content_length) -print(a.text) \ No newline at end of file +print(a.text) diff --git a/port/linux/test/requests-test.cpp b/port/linux/test/requests-test.cpp index 037734887..8f4316a85 100644 --- a/port/linux/test/requests-test.cpp +++ b/port/linux/test/requests-test.cpp @@ -274,7 +274,7 @@ TEST(requests, get_basic) { } //! Enable it manually if needed -#if 0 +#if 1 TEST(requests, post_data) { PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); extern unsigned char pikaModules_py_a[];