【发布时间】:2017-03-06 05:07:40
【问题描述】:
我的服务有两种方法 Get 和 Post。获取请求正在运行,但发布请求失败,提示未授权。
public getExercise(exerciseId): Observable<Exercise[]>{
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers, withCredentials: true });
return this.http.get(this.base_url + 'get_exercise/' + exerciseId + '/', options)
.map(this.extractData)
.catch(this.handleError);
}
public saveRating(value, exerciseId): Observable<Exercise[]>{
console.log(value + " " + exerciseId)
let headers = new Headers({ 'Content-Type': 'application/json' });
headers.append('Authorization','Basic')
let options = new RequestOptions({ headers: headers, withCredentials: true });
return this.http.post(this.base_url + 'save_progress/' + exerciseId + "/" + value + "/", options)
.map(this.extractData)
.catch(this.handleError);
}
获取:
发帖:
我在使用 Post 方法时做错了什么?我有来自我的 angular1 应用程序的原始代码:
var url = "/api/exercises/save_progress/" + exerciseType + "/" + rating + "/";
if($cookies.token){
$http.defaults.headers.common.Authorization = 'Token ' + $cookies.token;
}
【问题讨论】:
标签: angular django-rest-framework ionic2