我在節點 js expree 和 sequelize 中有后端,當我與郵遞員向我的后端提出請求時,我試圖獲取我所有的 product_types 這就是答案:
郵遞員 http 請求和標頭
但是當我在我的前端 angular 上做同樣的請求時,我得到了一個錯誤
header Authorization is missing
這是我的角度服務 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'
}
我不知道為什么不使用令牌發送授權令牌不為空
帶有令牌和錯誤的角度控制臺
uj5u.com熱心網友回復:
您的 HttpClientpost引數順序不正確..
post(url: string, body: any, options: { headers?: HttpHeaders....
第二個引數是主體post,第三個是帶有標題的選項
或者,也許您應該使用get- 在這種情況下,您可以按原樣保留引數
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/343782.html
