angular - 在发布请求时获得 403
问题描述
角 11
Stackblitz:https ://stackblitz.com/edit/github-vunq3e
我试图发出一个帖子请求以标记喜欢的曲目:
服务.ts
MarklikedSongs(id:any, status:boolean){
const token = "1072694e";
let headers = new HttpHeaders({
"Content-Type": "application/json",
"user-access-token": token
});
const httpOptions = {
headers: headers
};
return this.http.post(`https://api.sprintt.co/spotify/liked_tracks/${id}?status=${status}`, httpOptions);
}
组件.ts
markLikedSongs(id:any){
this.playListsAPI.MarklikedSongs(id,true).subscribe((data:any)=>{
this.likedSongs = data
console.log(" this.likedSongs:", this.likedSongs)
})
}
由于未知原因,我在尝试从客户端发出请求时收到 403 错误消息: “无法识别令牌”,或者更准确地说,令牌甚至没有发送到标头。尽管在 Postman 和我的其他 motheds 中一切都检查出来了..
解决方案
令牌在 Authorization 标头中传递。
试试这个:用 auth_token 替换你的令牌。
const headers = new Headers({
'Content-Type': 'application/json',
'Authorization': `Bearer ${auth_token}`
});
推荐阅读
- angular - Angular 后端 HTTP 请求
- python - Mixture parameters from a TensorFlow Probability mixture density network
- android - 有没有办法同时反编译多个android apk?
- angular - 运行 npm install 时出现 Angular 应用程序错误 - 无法解析依赖项
- html - img 选项卡可见性变为空白
- jointjs - 动态设置纸张模型
- regex - PowerShell 按模式提取
- python - 单击硒中的复选框
- sql - Spark 在读取具有表列显示名称的 teradata 表时遇到问题
- git - 通过 Jenkins 访问本地 git 存储库,而两者都在不同的机器上