I am developing a custom mobile application Vera with UI5. I am using HTTP requests with the built-in URL data_request.
I have already completed most basic functions such as login, controlling devices(Air Conditioners, Thermostats, Security Panels, Switches and so on), running scenes etc.
Now, I want to create scenes, triggers, schedules and be able to disable/enable them.
Actually I managed to do that using http://ip_address:3480/data_request?id=scene&action=create&json=valid_json command if Vera is in the local network. It work seamlessly in local area network. But if I communicate Vera through forward servers, the request fails depending on the length of HTTP request. If it is too long, it fails with a “ERROR” response.
I have analyzed what Vera Web Interface doing with Firebug. While creating or editing a scene, it uses ModifyUserData request with SOAP envelope which I would never prefer in a mobile application (Due to its performance).
Is there a way or workaround to work with long HTTP requests?
Thanks,
The length limit with GET is short and arbitrary. It depends a lot on the server, so if the server is reporting “request too long” you just can’t use GET.
You can try to use HTTP POST instead of GET, and put the parameters into the HTTP content instead of the request URL, appropriately escaped. But Vera might not accept it. Try it locally and see.
I had a similar problem when I wanted to call an action with an argument that was VERY LONG. If you are using JavaScript you can modify the following. It uses the RUN LUA request. It can have an arbitrarily long CODE body. This is how the LUA Test code is handled.
function va_UpdateProp(varName, varVal) {
var envelope='<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">';
envelope+='<s:Body>';
envelope+=' <u:' + HAG_RUN_LUA + ' xmlns:u="' + HAGEVICE_STYPE + '">';
envelope+=' <DeviceNum></DeviceNum>';
envelope+=' <Code>luup.call_action("' + va_Properties.Svs + '", "SetProperty", {PropertyName="' + varName + '", PropertyValue="' + xml_encode(varVal) + '"}, ' + va_Properties.deviceID + ')</Code>';
envelope+=' </u:' + HAG_RUN_LUA + '>';
envelope+='</s:Body>';
envelope+='</s:Envelope>';
var requestHeaders = {};
requestHeaders['Content-type'] = 'text/xml;charset=UTF-8';
requestHeaders['MIME-Version'] = '1.0';
requestHeaders["SOAPACTION"] = '"' + HAGEVICE_STYPE + '#' + HAG_RUN_LUA + '"';
new Ajax.Request(command_url + '/upnp/control/hag', {
method:'post',
requestHeaders:requestHeaders,
parameters: envelope,
onSuccess: function(transport) {
},
onFailure: function(transport) {
alert("Failure");
}
});
}
Thank you all,
I managed to send long request using HTTP headers both locally and remotely.
I constructed URL as follows http://ip_address:3480/data_request?id=scene&action=create and then put json=valid_json parameter into HTTP header.
Putting parameters into HTTP content (body) did not work and plus I generally don’t prefer SOAP actions in mobile apps.