Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

AngularJS Post and CORS

$
0
0

Hi,
i try to do a sample $http.post request to sign in user with the same API i use for my website but i have a CORS problem. I have read a lot of post in internet, and i have tried a lot of solution but i don't arrived to do the post request...
So, my backend is a nodeJS and i have this cors configuration with this api :

app.use(function(req, res, next) {
console.log(req.headers);
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "origin,x-requested-with,content-type,accept,x-www-form-urlencoded,json");
res.header("Access-Control-Allow-Methods", "OPTIONS,POST,GET,PUT,DELETE");
next(); });
app.post('api/authenticate', function() { // do something }

i try to call it with Postman (the google chrome app) and it work fine. i haven't any problem. When i try to call this api with angular (not only in ionic, i have made a little angular website to try) i have an OPTIONS request which return 403...
In the nodejs configuration i have print the angular header and i have this :

   { host: 'localhost:8070', // my api adress
  connection: 'keep-alive',
  'access-control-request-method': 'POST',
  origin: 'http://192.168.1.10:8100', // ionic serveur adress
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
  'access-control-request-headers': 'accept, content-type',
  accept: '*/*',
  referer: 'http://192.168.1.10:8100/',
  'accept-encoding': 'gzip, deflate, sdch',
  'accept-language': 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4' }

Can you help me ? An other method like used AFNetworking than angularJs is better ?
Thanks in advance. i'm sorry for my approximate english...
Have a good day.


Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>