【发布时间】:2018-08-27 15:06:45
【问题描述】:
我正在尝试发送登录详细信息,但响应错误是
显示缺少 csrf 令牌。我如何从 Angular 2 发送 csrf 令牌
后端 Django。
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders} from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Cookie } from 'ng2-cookies';
import 'rxjs/add/operator/map';
@Injectable()
export class AuthenticationService {
constructor(private http: HttpClient){}
login(username:string,password:string){
return this.http.post<any>('/api/auth',{username:username,password:password},)
.map(user => {
//login successful if there a jwt token in the response
if(user && user.token){
localStorage.setItem('currentUser',JSON.stringify(user));
}
return user;
})
}
logout(){
//remove user from local storage to log user out
localStorage.removeItem('CurrentUser');
}
}
【问题讨论】:
标签: javascript angular2-routing csrf