Changing ngResource save and using CORS (Cross Domain)

Asked

Viewed 124 times

1

I’m developing an angled application, and I’m having a problem with the ngResource module.

I need to call a URL from another system, for that I already added the necessary headers in the other application. However in my request I need to call using a Content-type: application/x-www-form-urlencoded, for this I changed the save method of $Resource. More when I make the change it stops making the requests in CORS and presents the error below.

No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost' is therefore not allowed access.

This error is only presented when I change the headers of save method follows below the way I am changing.

$resource(config.url.generalSystems + '/index.php',{},{save:{headers: {'Content-Type': 'application/x-www-form-urlencoded'}, method: 'POST'}}).save("Action=Login&validator=&RequestedURL=&Lang=pt_BR&TimeOffset=&User="+Login+"&Password="+Senha, function (retorno) {
     console.log(retorno);
}

Below follows the code that works using CORS, however it does not send the Content-type: application/x-www-form-urlencoded he sends the Content-type: application/json, and cannot because it is not compatible with the other application.

$resource(config.url.generalSystems + '/index.php').save({Action : 'Login', validator : '', RequestedURL : '', Lang : 'pt_BR', TimeOffset : '', User : Login, Password : Senha}, function (retorno) {
    console.log(retorno);
}

What I need to do to make CORS work in the first example?

Note: Access-Control-Allow-Origin: * / * and Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept have been added

  • A similar question here: http://stackoverflow.com/a/27668794/1310945 - take a look to see if it helps you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.