AngularJS $http provider not passing cookies to .NET Web Service -


i having problems using $http provider in angularjs make api call .net backend requires authentication. .net backend service expects ".aspxauth" , "__requestverificationtoken" cookies included in call.

when use plain js , .ajax, passing cookies in beforesend block works.

$.ajax({ url: server_url + '/api/accounts', type: 'get', datatype: 'json', crossdomain: true, xhrfields: { withcredentials: true }, success: function(data, status){ // ... }, error: function (request, textstatus, errorthrown) { // ... }, beforesend: function (req) {     req.setrequestheader("cookie", request_ver_token);     req.setrequestheader("cookie", aspxauth_token); } }); 

in angularjs, i've tried setting in $httpprovider , in $http call without success:

(in config block):

// ... app.config(function ($routeprovider, $httpprovider) { $httpprovider.defaults.headers.common[".aspxauth"] = '....'; $httpprovider.defaults.headers.common["__requestverificationtoken"] = '....'; $httpprovider.defaults.usexdomain = true;  // ... 

(in $http call):

  $http({ url: 'http://server_url/api/accounts', method: 'get',           {headers: {           '__requestverificationtoken': '....',           '.aspxauth': '....'           }}           }) .success(function(data, status, headers, config) {     // ...          }) .error(function (data, status, headers, config) {     // ...          }); 

i 401 unauthorised error. if authorization block removed server code, code works without needing insert headers. how emulate same beforesend block in angularjs , ensure cookies passed server during api call?

did try pass header parameters not in json object directly headers attribute?

$http({ url: 'http://server_url/api/accounts', method: 'get',       headers: {       '__requestverificationtoken': '....',       '.aspxauth': '....'       } }).success(function(data, status, headers, config) { // ...      }) .error(function (data, status, headers, config) { // ... }); 

hope can help.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -