【发布时间】:2021-12-15 19:33:55
【问题描述】:
我在节点 js expree 中有后端,当你向我的后端提交邮递员申请时,我试图获取我所有的 product_types 这就是答案:
postman http request and header
但是当我在前端 angular 上做同样的请求时,我得到了一个错误
header Authorization is missing
这是我的 Angular 服务 http 请求
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});
}
这是发送到我的邮递员后端的标头
{
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'
}
{
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'
}
我不知道为什么不使用令牌发送授权 令牌不为空
【问题讨论】:
标签: angular typescript https xmlhttprequest http-headers