javascript - Fetch POST with some headers -
i want post data using fetch
function. i've been testing curl
command aim of find correct response. found command works want looks 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 problem in http version or other headers settings receive error response.
fetch
api uses promises
handle callback results.
in case:
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>') }).catch(function(err) { // error :( });
also, content-type
should "application/json; charset=utf-8"
.
Comments
Post a Comment