我在我的应用程序中使用基于令牌的身份验证 我的后端是使用restful service(spring)开发的.后端代码很好地生成了所需的访问令牌和刷新令牌的时间轴,所以我已经覆盖了以下的http类:
export class customHttp extends Http {
headers: Headers = new Headers({ 'Something': 'Something' });
options1: RequestOptions = new RequestOptions({ headers: this.headers });
private refreshTokenUrl = AppSettings.REFRESH_TOKEN_URL;
constructor(backend: ConnectionBackend,
defaultOptions: RequestOptions,private refresh:OauthTokenService) {
super(backend, defaultOptions);
}
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
console.log("custom http ");
return super.request(url, options)
.catch((err) => {
if (err.status === 401) {
console.log(" custome http 401 ");
// refresh the token
this.refresh.refresh().subscribe((tokenObj)=>{
console.log("tokenobj ");
})
} else {
console.log("err " + err); …Run Code Online (Sandbox Code Playgroud) obj={
"candidateFeedbackQuestionInfoId": 8
};
jsonobj=JSON.stringify(this.obj);
return this.http.delete(this.feebackUrl,this.jsonobj).map(this.extractData);
Run Code Online (Sandbox Code Playgroud)
如果我们传递body来删除它会抛出类型不匹配错误,任何帮助都会很棒