$http.post adding a authorization header


#1

HI There

I am try to do a post to a webservice that requires an authorization error.

I have tried numerous things and browsed the internet but nothing I try seems to be working.

Here is the code

.service('UserSettings', ['$http', function($http){

    var api_geturl = 'myurl';
    var api_updateurl = 'myurl';
    var token = localStorage.getItem("token");
    
    let headers = new Headers();  
         headers.append('Authorization', "Bearer " + token );  
    let _body = {};
    
    var ret = {
        getUserSettings: function(){
           return $http.post(api_geturl, _body, headers).then(function(resp){
                 return resp;
            })
        },
         updateUserSettings: function(data){
           return $http.post(api_updateurl, data , headers).then(function(resp){
                 return resp;
            })
        },
        
    }
    
    return ret;

}]);

Request Below

Request URL:myurl
Request Method:POST
Status Code:401 Unauthorized
Remote Address:40.69.88.149:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Origin:*
Cache-Control:no-cache, no-store
Content-Length:205
Content-Type:application/json; charset=utf-8
Date:Tue, 05 Dec 2017 17:00:50 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.0
Set-Cookie:Abp.Localization.CultureName=en; expires=Thu, 05-Dec-2019 17:00:51 GMT; path=/
Set-Cookie:ARRAffinity=3476a45ffaf68d2bcdb985995034447d94fa4df1ae54a194b813620782b22d6c;Path=/;HttpOnly;Domain=buygaloo.azurewebsites.net
WWW-Authenticate:Bearer
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Request Headers
view source
Accept:application/json, text/plain, /
Accept-Encoding:gzip, deflate, br
Accept-Language:en-ZA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7
Connection:keep-alive
Content-Length:2
Content-Type:application/json;charset=UTF-8
Host:buygaloo.azurewebsites.net
Origin:https://creator.ionic.io
Referer:https://creator.ionic.io/app/designer/8209808ef8d6
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
Request Payload
view source
{}
No properties


#2

got answer dont worry about this