0

我有一个在连接到我的家庭网络的 Raspberry Pi 上运行的 UPNP MPD 服务器。

我正在尝试通过 Tabris 应用程序控制它。

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);
    });

此代码返回400 bad request错误。但是,运行 curl 请求确实有效

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

我认为这是预检请求的问题,但不知道如何纠正。

处理此类 API 请求的具体方法是什么?代码哪里出了问题?

4

0 回答 0