AngularJS - Cannot set Authorization in request headers

14 views
Skip to first unread message

Amarin

unread,
Nov 1, 2017, 5:27:53 AM11/1/17
to Angular and AngularJS discussion
I've tried many different ways to set header
with $http.defaults.headers.common.Authorization = 'Bearer ' + token;
in the config and in the $http get parameters.

No matter what, it does not get included into the headers.

Here is the AngularJS request headers printout from the server.

INFO: access-control-request-headers/authorization
INFO: connection/keep-alive
INFO: accept-language/en-US,en;q=0.8
INFO: host/tc:8080
INFO: accept/*/*
INFO: access-control-request-method/GET
INFO: user-agent/Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) 
INFO: accept-encoding/gzip, deflate

And here is the printout from Postman client

INFO: cache-control/no-cache
INFO: connection/keep-alive
INFO: accept-language/en-US,en;q=0.8,th;q=0.6
INFO: host/tc:8080
INFO: accept/*/*
INFO: postman-token/7dbcb478-a02b-a4de-e87d-
INFO: authorization/Bearer jK572w/FKLAPFU5OkZBLHanWuf3kmHy456SM6UZnRSjmyM+4Job1Zw63i61ebowO
INFO: user-agent/Mozilla/5.0 (Windows NT 6.1) 
INFO: accept-encoding/gzip, deflate

On the postman the token key is received by the server with key 'authorization'. But there's no authorization key from AngularJS only as value of access-control-request-headers

Please see if I'm missing something. Do I need a library? I searched many topics on stackoverflow but no answers.
Thank you.
Reply all
Reply to author
Forward
0 new messages