davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.01k stars 250 forks source link

can not get post data by example "post" #287

Open wjefen opened 3 years ago

wjefen commented 3 years ago

i send date by curl,but can't get any data i trace it, the dict's key was data,not content-type,is it bug?

debug info: onion_dict_find_node (d=0x615df0, current=0x62a220, key=0x400e58 "application", parent=0x0) at */onion-master/src/onion/dict.c:231 231 if (!current) { (gdb) n 234 int cmp = d->cmp(key, current->data.key); (gdb) p key $79 = 0x400e58 "application" #### I modify the example (text->application) (gdb) p current->data.key #### it is debug data saved to dict $80 = 0x615da0 "{\"input_1\": \"111sunshine\"}"

the cmd i used: curl --trace test.txt --data '{"input_1": "111sunshine"}' http://127.0.0.1:8080/data

davidmoreno commented 3 years ago

Can you try using onion_request_get_data.

wjefen commented 3 years ago

the req->data is null (gdb) p *req $2 = {connection = {listen_point = 0x615280, user_data = 0x0, fd = 7, cli_addr = {ss_family = 2, __ss_padding = "\231\026\177\000\000\001", '\000' <repeats 111 times>, __ss_align = 0}, cli_len = 16, cli_info = 0x0}, flags = 273, fullpath = 0x615310 "/data", path = 0x615315 "", headers = 0x62a1a0, GET = 0x615330, POST = 0x615df0, FILES = 0x0, session = 0x0, data = 0x0, cookies = 0x0, session_id = 0x0, parser = 0x7ffff79bf73f , parser_data = 0x628180, websocket = 0x0, free_list = 0x615dd0}

if I input the format as --data "key1=xx&key2=xxx",onion_request_get_post(x,key1)can get the data,

in the func "parse_POST_urlencode",token->extra can get the raw data,but "token->extra = NULL" before return " will dissipates it i donot know how to get raw data

Can you try using onion_request_get_data.

wjefen commented 3 years ago

onion_request_get_data will get req->data

the req->data is null (gdb) p *req $2 = {connection = {listen_point = 0x615280, user_data = 0x0, fd = 7, cli_addr = {ss_family = 2, __ss_padding = "\231\026\177\000\000\001", '\000' <repeats 111 times>, __ss_align = 0}, cli_len = 16, cli_info = 0x0}, flags = 273, fullpath = 0x615310 "/data", path = 0x615315 "", headers = 0x62a1a0, GET = 0x615330, POST = 0x615df0, FILES = 0x0, session = 0x0, data = 0x0, cookies = 0x0, session_id = 0x0, parser = 0x7ffff79bf73f , parser_data = 0x628180, websocket = 0x0, free_list = 0x615dd0}

if I input the format as --data "key1=xx&key2=xxx",onion_request_get_post(x,key1)can get the data,

in the func "parse_POST_urlencode",token->extra can get the raw data,but "token->extra = NULL" before return " will dissipates it i donot know how to get raw data

Can you try using onion_request_get_data.

i have debuged it ,onion_request_get_data will get req->data

wjefen commented 3 years ago

oh,I can get raw data by req->POST->root->data->key, the data is Unique key of the dictionary, is it not support api to get this? I has seen the code of "examples\jsonrpc\jsonrpc.c",the callback fun will call onion_request_get_data,the func will return req->data I debuged it ,the req->data was NULL, only Through by POST(dict),why?