• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Webserver (REST API) - POST
#1
Is it possible to control the webservice (REST API) with a POST request in pilight 8.0?
GET is working fine:
Code:
http://raspberrypi-prd:5001/control?device=koplamp&state=off

However when I send a POST request:
Code:
http://raspberrypi-prd:5001/control
BODY
data:device=koplamp&state=on

pilight is going down with this error:
Code:
[Oct 25 19:50:06:322377] pilight-daemon: INFO: client connected, ip 10.0.0.73, port 59388
-- STACKTRACE (4 FRAMES) --
webserver_mimetype             ip = 0x7672a5d8, sp = 0x713f5898
webserver_clientize            ip = 0x7672ca34, sp = 0x713f5898
clone                          ip = 0x76456be8, sp = 0x713f5898
segmentation fault
What do I wrong?
 
Reply
#2
What happened is that you found a bug Smile The REST API doesn't support POSTS, but also doesn't handle this as it should (ie. an normal error message).
 
Reply
#3
Okay Unsure. here you have the debug info

Code:
(gdb) backtrace
#0  0x767c81c8 in array_free () from /usr/local/lib/libpilight.so
#1  0x767f8948 in ?? () from /usr/local/lib/libpilight.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)
(gdb) frame 1
#1  0x767f8948 in ?? () from /usr/local/lib/libpilight.so
(gdb) frame 0
#0  0x767c81c8 in array_free () from /usr/local/lib/libpilight.so
(gdb)
 
Reply
#4
When using gdb, first install the piligh-gdb package.

I just checked myself but can't confirm (in version 8.0):
Code:
# curl -d "device=switch&state=on" -X POST http://10.0.0.212:5001/control
{"message":"success"}
 
Reply
#5
Smile 2nd try

Code:
(gdb) backtrace
#0  0x767c81c8 in array_free (array=0x714fa244, len=2) at /home/pilight/source/test/libs/pilight/core/common.c:109
#1  0x767f8948 in webserver_parse_rest (conn=0x725004dc) at /home/pilight/source/test/libs/pilight/core/webserver.c:263
#2  0x767f95d8 in webserver_request_handler (conn=0x725004dc) at /home/pilight/source/test/libs/pilight/core/webserver.c:459
#3  0x767fba34 in webserver_handler (conn=0x725004dc, ev=MG_REQUEST) at /home/pilight/source/test/libs/pilight/core/webserver.c:926
#4  0x767e1218 in call_user (conn=0x725004d8, ev=MG_REQUEST) at /home/pilight/source/test/libs/pilight/core/mongoose.c:1837
#5  0x767e77d8 in call_request_handler (conn=0x725004d8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:3069
#6  0x767e86a4 in call_request_handler_if_data_is_buffered (conn=0x725004d8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:3331
#7  0x767ecbc0 in on_recv_data (conn=0x725004d8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:4396
#8  0x767ee68c in mg_ev_handler (nc=0x72500470, ev=3, p=0x714fc4f8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:4919
#9  0x767ddd28 in ns_call (nc=0x72500470, ev=3, p=0x714fc4f8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:523
#10 0x767df02c in ns_read_from_socket (conn=0x72500470) at /home/pilight/source/test/libs/pilight/core/mongoose.c:972
#11 0x767dfa2c in ns_mgr_poll (mgr=0x33660, milli=1000) at /home/pilight/source/test/libs/pilight/core/mongoose.c:1117
#12 0x767ed668 in mg_poll_server (server=0x33660, milliseconds=1000) at /home/pilight/source/test/libs/pilight/core/mongoose.c:4595
#13 0x767faf0c in webserver_worker (param=0x0) at /home/pilight/source/test/libs/pilight/core/webserver.c:772
#14 0x76664fc4 in start_thread (arg=0x714ff470) at pthread_create.c:335
#15 0x76525be8 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:76 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) frame 15
#15 0x76525be8 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:76 from /lib/arm-linux-gnueabihf/libc.so.6
76      ../sysdeps/unix/sysv/linux/arm/clone.S: Bestand of map bestaat niet.
(gdb) frame 14
#14 0x76664fc4 in start_thread (arg=0x714ff470) at pthread_create.c:335
335     pthread_create.c: Bestand of map bestaat niet.
(gdb) frame 13
#13 0x767faf0c in webserver_worker (param=0x0) at /home/pilight/source/test/libs/pilight/core/webserver.c:772
772     /home/pilight/source/test/libs/pilight/core/webserver.c: Bestand of map bestaat niet.
(gdb) frame 12
#12 0x767ed668 in mg_poll_server (server=0x33660, milliseconds=1000) at /home/pilight/source/test/libs/pilight/core/mongoose.c:4595
4595    /home/pilight/source/test/libs/pilight/core/mongoose.c: Bestand of map bestaat niet.
(gdb) frame 11
#11 0x767dfa2c in ns_mgr_poll (mgr=0x33660, milli=1000) at /home/pilight/source/test/libs/pilight/core/mongoose.c:1117
1117    in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 10
#10 0x767df02c in ns_read_from_socket (conn=0x72500470) at /home/pilight/source/test/libs/pilight/core/mongoose.c:972
972     in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 9
#9  0x767ddd28 in ns_call (nc=0x72500470, ev=3, p=0x714fc4f8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:523
523     in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 8
#8  0x767ee68c in mg_ev_handler (nc=0x72500470, ev=3, p=0x714fc4f8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:4919
4919    in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 7
#7  0x767ecbc0 in on_recv_data (conn=0x725004d8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:4396
4396    in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 6
#6  0x767e86a4 in call_request_handler_if_data_is_buffered (conn=0x725004d8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:3331
3331    in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 5
#5  0x767e77d8 in call_request_handler (conn=0x725004d8) at /home/pilight/source/test/libs/pilight/core/mongoose.c:3069
3069    in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 4
#4  0x767e1218 in call_user (conn=0x725004d8, ev=MG_REQUEST) at /home/pilight/source/test/libs/pilight/core/mongoose.c:1837
1837    in /home/pilight/source/test/libs/pilight/core/mongoose.c
(gdb) frame 3
#3  0x767fba34 in webserver_handler (conn=0x725004dc, ev=MG_REQUEST) at /home/pilight/source/test/libs/pilight/core/webserver.c:926
926     /home/pilight/source/test/libs/pilight/core/webserver.c: Bestand of map bestaat niet.
(gdb) frame 2
#2  0x767f95d8 in webserver_request_handler (conn=0x725004dc) at /home/pilight/source/test/libs/pilight/core/webserver.c:459
459     in /home/pilight/source/test/libs/pilight/core/webserver.c
(gdb) frame 1
#1  0x767f8948 in webserver_parse_rest (conn=0x725004dc) at /home/pilight/source/test/libs/pilight/core/webserver.c:263
263     in /home/pilight/source/test/libs/pilight/core/webserver.c
(gdb) frame 0
#0  0x767c81c8 in array_free (array=0x714fa244, len=2) at /home/pilight/source/test/libs/pilight/core/common.c:109
109     /home/pilight/source/test/libs/pilight/core/common.c: Bestand of map bestaat niet.
(gdb)
 
Reply
#6
What program are you using to do the POST? Can you post the command or code?
 
Reply
#7
With postmen, I've attached a screenshot.
Code:
https://www.getpostman.com/


Attached Files
.png   postman-pilight.png (Size: 56.92 KB / Downloads: 8)
 
Reply
#8
What pilight version are you running?

I've tried postman myself but it just works fine. I must notice that your POST is invalid though. What i'm expecting is:
Code:
POST /control HTTP/1.1
Host: 10.0.0.212:5001
Cache-Control: no-cache
Postman-Token: 591e109c-9ff1-7c86-5fa1-b4437c150506

device=switch&state=off

And not what you're sending:
Code:
POST /control HTTP/1.1
Host: 10.0.0.212:5001
Cache-Control: no-cache
Postman-Token: 6769ac2d-63f0-b8b2-cd63-469efb632a95
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="data"

device=switch&state=off:
------WebKitFormBoundary7MA4YWxkTrZu0gW--
This POST header is only used when sending binary files like with <input type="file" />, which doesn't make sense with the pilight REST API.

But still, i can't get pilight to fail even with the multipart/form-data header.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  [Already fixed in 8.1.2] Loss of webserver-connection Ulrich.Arnold 34 2,485 08-02-2019, 02:25 PM
Last Post: curlymo
  REST API problem kaku_screen_old / elro_800_switch with pilight 8.1.4 pisperate 4 473 12-20-2018, 09:26 PM
Last Post: pisperate
  webserver-authentication problem with some browsers MorfelPi 4 1,855 09-21-2016, 06:59 PM
Last Post: Emiks5
  Using API webserver send page "message":"failed" fips 1 1,514 01-08-2016, 09:21 AM
Last Post: fips
  REST API - send behaviour joho 1 1,590 12-13-2015, 09:22 PM
Last Post: woutput
  webserver-authentication Luppie 6 2,821 08-03-2015, 03:31 PM
Last Post: curlymo
  Rest API in nightly Image seems not to work spooniester 2 1,939 06-25-2015, 10:07 AM
Last Post: spooniester
  getting values from pilight if webserver-authentication enabled shelby_cobra 2 1,769 06-03-2015, 11:35 PM
Last Post: shelby_cobra
  [Fully Supported] SSL support in webserver? Karel 18 11,361 05-29-2015, 10:26 PM
Last Post: curlymo
  Using API webserver send page gerrit312 5 3,479 05-28-2015, 01:37 PM
Last Post: diman87

Forum Jump:


Browsing: 1 Guest(s)