# $http.post adding a authorization header

**URL:** <https://forum.ionicframework.com/t/http-post-adding-a-authorization-header/114440>\
**Category:** ionic-v1\
**Created:** [December 5, 2017, 5:02pm UTC](https://forum.ionicframework.com/t/http-post-adding-a-authorization-header/114440 "2017-12-05T17:02:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![StantonRoux](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/stantonroux/32/124354_2.png) [@StantonRoux](https://forum.ionicframework.com/u/StantonRoux)\
**Post date:** [December 5, 2017, 5:02pm UTC](https://forum.ionicframework.com/t/http-post-adding-a-authorization-header/114440/1 "2017-12-05T17:02:36Z")

</div>

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

```auto
.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](http://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](https://creator.ionic.io)  
Referer:[https://creator.ionic.io/app/designer/8209808ef8d6](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

---

<div class="post-metadata">

**Author:** ![StantonRoux](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/stantonroux/32/124354_2.png) [@StantonRoux](https://forum.ionicframework.com/u/StantonRoux)\
**Post date:** [December 5, 2017, 5:53pm UTC](https://forum.ionicframework.com/t/http-post-adding-a-authorization-header/114440/2 "2017-12-05T17:53:32Z")

</div>

got answer dont worry about this

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:00pm UTC](https://forum.ionicframework.com/t/http-post-adding-a-authorization-header/114440/3 "2021-07-19T22:00:48Z")

</div>

Closed on July 19, 2021, 10:00pm UTC


