具体来说,我不知道标题应该是什么样子。
使用具有授权功能的Postman调用API。我的API托管在localhost:44320上,但我没有部署它。
在React中,我使用'react-azure-adb2c'库,它也可以工作。我可以登录,然后获得所有需要的令牌。
var token = auth.getToken(); //here is the token which is correct
fetch("https://localhost:44320/api/worker/", {
method: "GET",
headers: {
Authorization: token,
Accept: "application/json",
Host: "localhost:44320"
}
})
.then(res => res.json())
.then(json => this.setState({ listOfWorkers: json.results }));
}
您将标题指定为Authorization: Bearer token-value-here
。