Fcojriosbello Fcojriosbello - 3 months ago 17
Javascript Question

Fetch POST with some headers

I want to POST some data using

fetch
function. I've been testing with
curl
command with the aim of find the correct response. Then I found that the command that works as I want looks like this:

curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' -s http://192.168.1.48:49153/upnp/control/basicevent1


The parameters of
fetch
that I've setted:

fetch('http://192.168.1.48:49153/upnp/control/basicevent1', {
method: 'POST',
headers: {
'Accept' : '',
'Content-type': text/xml; charset="utf-8",
'SOAPACTION': "urn:Belkin:service:basicevent:1#SetBinaryState"
},
body: ('<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>')
})


I don't know if the problem is in the HTTP version or other headers settings but I receive an error response.

Answer

At the end I modified the request. The problem was the content time and some fields within the body.

'Content-type': 'text/xml; charset=utf-8',