Skip to content

Commit e98e73e

Browse files
committed
update requests POST test server url
1 parent 423130f commit e98e73e

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

examples/requests/post_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
header = {"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryrEPACvZYkAbE4bYB"}
55

6-
a = requests.request("POST", "http://pikascript.com/upload", headers=header, data=form_data)
6+
a = requests.request("POST", "http://httpbin.org/post",
7+
headers=header, data=form_data)
8+
9+
# a = requests.request("POST", "http://pikascript.com/uploads",
10+
# headers=header, data=form_data)
711

812
print(a.headers)
913
print(a.content_length)
10-
print(a.text)
14+
print(a.text)

package/requests/requests.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def request(
5656
files=None,
5757
json=None,
5858
data=None) -> Response:
59-
if files != None:
59+
if files is not None:
6060
print("files is not supported")
6161
return None
62-
if json != None:
62+
if json is not None:
6363
print("json is not supported")
6464
return None
6565
"""
@@ -69,25 +69,41 @@ def request(
6969
rqst.url = url
7070
# 初始化,分配内存, 写入方法POST/GET
7171
ret = rqst.request_init(method)
72+
# print("Request init ret: " + str(ret))
7273
if ret != 1:
74+
print("Failed to initialize the request object.")
7375
return None
76+
7477
# 写入URL
7578
ret = _append_params_to_url(rqst, url, params)
76-
if ret != 1:
79+
# print("Append params to URL ret: " + str(ret))
80+
if ret != 1:
7781
# 出现错误,需要释放对象
82+
print("Error appending params to the URL.")
7883
return None
84+
7985
# 写入默认HTTP版本号
8086
ret = rqst.proto_write('')
87+
# print("Write HTTP version ret: " + str(ret))
8188
if ret != 1:
89+
print("Error writing HTTP version.")
8290
return None
91+
8392
# 写入响应头数据
8493
ret = _append_headers(rqst, headers)
94+
# print("Append headers ret: " + str(ret))
8595
if ret != 1:
96+
print("Error appending headers to the request.")
8697
return None
98+
8799
ret = rqst.request(method, rqst.url, timeout, data)
100+
# print("Request ret: " + str(ret))
88101
if ret != 1:
102+
print("Request failed with response code: " + str(ret))
89103
return None
104+
90105
return rqst
91106

107+
92108
def get(url: str, params=None) -> Response:
93109
return request('GET', url, params)

port/linux/package/pikascript/requests.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def request(
5656
files=None,
5757
json=None,
5858
data=None) -> Response:
59-
if files != None:
59+
if files is not None:
6060
print("files is not supported")
6161
return None
62-
if json != None:
62+
if json is not None:
6363
print("json is not supported")
6464
return None
6565
"""
@@ -69,25 +69,41 @@ def request(
6969
rqst.url = url
7070
# 初始化,分配内存, 写入方法POST/GET
7171
ret = rqst.request_init(method)
72+
# print("Request init ret: " + str(ret))
7273
if ret != 1:
74+
print("Failed to initialize the request object.")
7375
return None
76+
7477
# 写入URL
7578
ret = _append_params_to_url(rqst, url, params)
76-
if ret != 1:
79+
# print("Append params to URL ret: " + str(ret))
80+
if ret != 1:
7781
# 出现错误,需要释放对象
82+
print("Error appending params to the URL.")
7883
return None
84+
7985
# 写入默认HTTP版本号
8086
ret = rqst.proto_write('')
87+
# print("Write HTTP version ret: " + str(ret))
8188
if ret != 1:
89+
print("Error writing HTTP version.")
8290
return None
91+
8392
# 写入响应头数据
8493
ret = _append_headers(rqst, headers)
94+
# print("Append headers ret: " + str(ret))
8595
if ret != 1:
96+
print("Error appending headers to the request.")
8697
return None
98+
8799
ret = rqst.request(method, rqst.url, timeout, data)
100+
# print("Request ret: " + str(ret))
88101
if ret != 1:
102+
print("Request failed with response code: " + str(ret))
89103
return None
104+
90105
return rqst
91106

107+
92108
def get(url: str, params=None) -> Response:
93109
return request('GET', url, params)

port/linux/test/python/requests/post_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
header = {"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryrEPACvZYkAbE4bYB"}
55

6-
a = requests.request("POST", "http://pikascript.com/upload", headers=header, data=form_data)
6+
a = requests.request("POST", "http://httpbin.org/post",
7+
headers=header, data=form_data)
8+
9+
# a = requests.request("POST", "http://pikascript.com/uploads",
10+
# headers=header, data=form_data)
711

812
print(a.headers)
913
print(a.content_length)
10-
print(a.text)
14+
print(a.text)

port/linux/test/requests-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ TEST(requests, get_basic) {
274274
}
275275

276276
//! Enable it manually if needed
277-
#if 0
277+
#if 1
278278
TEST(requests, post_data) {
279279
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
280280
extern unsigned char pikaModules_py_a[];

0 commit comments

Comments
 (0)