angularjs - How to send both data and header to a server? -


i want send header server using http call post request. when send header only, ok. when add data call, error:

http://localhost:3000/test_post.  request header field content-type not allowed access-control-allow-headers in preflight response. 

i use node.js server side language, code cors settings:

app.use(function(req, res, next) {  res.header("access-control-allow-origin", "*"); res.header("access-control-expose-headers", "x-auth");  res.header("access-control-allow-headers", "x-auth");   next(); }); 

this $http call angular:

 $http({     method: 'post',     data: {name: 'dani'},     url: 'http://localhost:3000/test_post'     headers: {         'x-auth': 'some token'     } }).then(function successcallback(response) {      console.log(response.data);  }, function errorcallback(response) {      console.log('error'); }); 

i know problem cors, don't know modify there, if remove res.header("access-control-allow-headers", "x-auth"); cors can data on server not header.

how can them both? hope can me that, thank you.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -