首页 > 解决方案 > 从 ionic 发送时 api 中的未定义索引授权

问题描述

我正在我的授权标头中将我的 JWT 令牌从本地存储发送到我的 API。一切都在 Postman 上运行,用户被添加到数据库中。但是,在我的 ionic 应用程序中,我不断收到未定义索引的错误。

添加患者

token = this.storage.get('token');

addPatient(FirstName, LastName, InjuryDesc, DOB) {
    const headers = new HttpHeaders();
    headers.set('Content-Type', 'application/json');
    headers.set('Authorization', 'Bearer + this.token');
    return this.http.post<any>(apiUrl + 'addPatient.php', 
                                {FirstName, LastName, InjuryDesc, DOB}, 
                                {headers});
}

php接口

$headers = getallheaders();
$jwt = $headers['Authorization'];


$response['jwt']= $jwt;

标签: phpionic-frameworkheaderauthorization

解决方案


推荐阅读