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:
local http = require("socket.http")
http.TIMEOUT = 5
local response_body = { }
local body =[[<?xml version="1.0" encoding="utf-8"?><AnalyticsEvent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:milestone-systems"><EventHeader><ID>00000000-0000-0000-0000-000000000000</ID><Timestamp>2017-05-02T20:48:12</Timestamp><Type>MyType</Type><Message>MyAnalyticsEvent01</Message><CustomTag>TagFromXML</CustomTag><Source><Name>192.168.1.32</Name></Source></EventHeader><Description>Analytics event description.</Description><Location>Event location 1</Location><Vendor><Name>My Smart Video</Name></Vendor></AnalyticsEvent>]]
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)
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:
http://forum.micasaverde.com/index.php?topic=30514.0But it is still not working correctly...
HELP

I hope I provided enough information so that anyone can help me get back on track...
Thanks in advance
With kind regards,
Jan