Hello,
After days of surfing the web, reading forum topics and creating requests in scenes, I feel defeated and need some fresh idea’s.
I’m trying to send a simple HTTP POST request to a Milestone XProtect system, containing an xml body.
Simple enough I would think…
Started by creating a scene in my Vera Edge.
Added the following code:
[code]
local http = require(“socket.http”)
http.TIMEOUT = 5
local response_body = { }
local body =[[<?xml version="1.0" encoding="utf-8"?>00000000-0000-0000-0000-0000000000002017-05-02T20:48:12MyTypeMyAnalyticsEvent01TagFromXML
local res, code, response_headers, status = http.request{
url = “http://192.168.1.116:9090”,
sink = ltn12.sink.table(response_body),
headers = {
[“Content-Type”] = “text/xml”,
[“Content-Length”] = tostring(body:len()),
[“Connection”] = “Keep-Alive”
},
source = ltn12.source.string(body),
method = “POST”
}
luup.task('Response: = ’ … table.concat(response_body) … ’ code = ’ … code … ’ status = ’ … status,1,‘Sample POST request with JSON data’,-1)[/code]
When triggering this scene, it runs, but I get a message: Sample POST request with JSON data : Response: = Error: Invalid data code = 400 status = HTTP/1.1 400 Bad Request
Using wireshark on the server monitoring port 9090 I see there is a partial packet, the server response with 400 and after the response there is the rest of the POST (2 segments?)
Using a custom program to send the same xml data, all works fine. (Attached are both the wireshark captures)
I found things like this: [url=http://forum.micasaverde.com/index.php?topic=30514.0]http://forum.micasaverde.com/index.php?topic=30514.0[/url]
But it is still not working correctly…
HELP :o
![]()
I hope I provided enough information so that anyone can help me get back on track…
Thanks in advance
With kind regards,
Jan