授权错误 header angular http
error with authorization header angular http
我在 node js expree 和 sequelize 中有后端,我试图得到我所有的 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});
}
这是转到我的邮递员后端的 header
{
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'
}
这个来自我的 angular 前端
{
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 consol with the token and the error
您的 HttpClient post
参数顺序不正确..
post(url: string, body: any, options: { headers?: HttpHeaders....
第二个参数是post
的body,第三个是headers
的选项
或者,也许您应该使用 get
- 在这种情况下,您可以保持参数不变
我在 node js expree 和 sequelize 中有后端,我试图得到我所有的 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});
}
这是转到我的邮递员后端的 header
{
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 consol with the token and the error
您的 HttpClient post
参数顺序不正确..
post(url: string, body: any, options: { headers?: HttpHeaders....
第二个参数是post
的body,第三个是headers
或者,也许您应该使用 get
- 在这种情况下,您可以保持参数不变