Skip to content

Commit

Permalink
update requests POST test server url
Browse files Browse the repository at this point in the history
  • Loading branch information
pikasTech committed Oct 11, 2024
1 parent 423130f commit e98e73e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
8 changes: 6 additions & 2 deletions examples/requests/post_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
print(a.text)
22 changes: 19 additions & 3 deletions package/requests/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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)
22 changes: 19 additions & 3 deletions port/linux/package/pikascript/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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)
8 changes: 6 additions & 2 deletions port/linux/test/python/requests/post_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
print(a.text)
2 changes: 1 addition & 1 deletion port/linux/test/requests-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit e98e73e

Please sign in to comment.