获取API发布XML请求错误

时间:2017-10-05 19:33:09

标签: javascript soap xmlhttprequest fetch-api

我无法执行fetch POST请求。它返回400 bad request错误

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

但是这个卷曲请求有效

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

所以我知道正文和标题内容是正确的。但我在fetch请求的哪里出错了?

0 个答案:

没有答案