I have a UPNP MPD server running on a Raspberry Pi connected to my home network.
I am trying to control it through the Tabris app.
fetch('http://192.168.1.6:49152/ctl/RenderingControl', {
method: 'POST',
headers: {
"SOAPAction": "urn:schemas-upnp-org:service:RenderingControl:1#GetVolume",
"Content-Type": "text/xml; charset=utf-8"
},
body: '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <s:Body><u:GetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetVolume></s:Body></s:Envelope>'
}).then(function (response) {
console.log(response.text());
}).catch(function (error) {
console.log('Request failed', error);
});
This code return a 400 bad request
error. However, running a curl request does work
echo '
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
<InstanceID>0</InstanceID>
<Channel>Master</Channel>
</u:GetVolume>
</s:Body>
</s:Envelope>
' | curl -v -d @- \
-H 'SOAPAction: "urn:schemas-upnp-org:service:RenderingControl:1#GetVolume"' \
-H 'content-type: text/xml; charset="utf-8"' \
http://192.168.1.6:49152/ctl/RenderingControl
I think it is an issue with preflight requests but not sure how to correct this.
What exactly is the way to deal with such API requests? Where in the code is the trouble?