javascript - Access-Control-Allow-Origin:* not being recognized by Angular.js $http -
i'm developing javascript app control smart tvs angular pre lights options requests before try post request (soap) i'm trying send. devices return response proper access-control-allow-origin: *
angular refuses send post request.
of course, can't change configurations of device's server send header angular "needs" , need send cookie
, content-type
.
how can work around this?
update screenshot of request (bottom) , response (top) headers.
update related angular code:
app configured with:
app.config(['$httpprovider',function($httpprovider) { $httpprovider.defaults.withcredentials = true; }])
the request is:
var 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:x_sendircc xmlns:u="urn:schemas-sony-com:service:ircc:1"><ircccode>{command}</ircccode></u:x_sendircc></s:body></s:envelope>'; var headers = { "content-type": "text/xml; charset=utf-8", "soapaction": "urn:schemas-sony-com:service:ircc:1#x_sendircc" }; return $http({ method:"post", url: "http://{ip}/sony/ircc".replace("{ip}", config.ip), data: body.replace("{command}", signal), headers: headers });
i believe problem withcredentials
. when use withcredentials
, server must indicate allows credentials. in simple get
request doesn't require preflighting, browser supposed keep such response app; in preflighted request, should not send actual request.
here best description @ mozilla https://developer.mozilla.org/en-us/docs/web/http/access_control_cors#requests_with_credentials
it says:
but browser reject response not have access-control-allow-credentials: true header, , not make response available invoking web content
if @ preflight response, see headers:
access-control-allow-headers: "content-type,soapaction" access-control-allow-origin: "*"
but required access-control-allow-credentials
header not there.
Comments
Post a Comment