i have backend in node js expree and sequelize im trying to get all my product_types when y made the peticion with postman to my backend this is the answer:
postman http request and header
but when i make the same peticion on my frontend angular i got a error
header Authorization is missing
this is my angular services http request
getTypes(token:any):Observable<any>{
let headers = new HttpHeaders().set('Content-Type', 'application/json')
.set('Authorization', token);
console.log(headers)
return this._http.post(this.url 'productType/getall', {headers:headers});
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
this is the header that goes to my postman backend
{
authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InN1YiI6MSwibmFtZSI6ImFkbWluIiwic3VybmFtZSI6ImFkbWluIiwicm9sZSI6InVzZXJfYWRtaW4iLCJpYXQiOjE2MzU2ODA3ODZ9LCJpYXQiOjE2MzU2ODA3ODYsImV4cCI6MTYzNTc2NzE4Nn0.9e-sP6ZnUeYe0EEpuLyQmxvIu7-U1_oXLZlt76XbBs0',
'user-agent': 'PostmanRuntime/7.28.3',
accept: '*/*',
'cache-control': 'no-cache',
'postman-token': 'b97c28a2-f88e-4953-93d5-199fd1443d77',
host: 'localhost:3002',
'accept-encoding': 'gzip, deflate, br',
connection: 'keep-alive',
'content-length': '0'
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
and this one is from my angular frontend
{
host: 'localhost:3002',
connection: 'keep-alive',
'content-length': '476',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
'sec-ch-ua-mobile': '?1',
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95
.0.4638.54 Mobile Safari/537.36',
'sec-ch-ua-platform': '"Android"',
origin: 'http://localhost:4200',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
referer: 'http://localhost:4200/',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'es-ES,es;q=0.9,en;q=0.8'
}
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
i dont know why isnt sending the authorization with the token the token isn't null
angular consol with the token and the error
CodePudding user response:
Your HttpClient post
params are not in the correct order..
post(url: string, body: any, options: { headers?: HttpHeaders....
The 2nd param is the body of the post
, 3rd is the options with headers
Or, maybe you should be using get
- in which case you'd keep your params as is