【发布时间】:2017-12-11 12:26:55
【问题描述】:
我在 Angular 4 中编写了一个调用 REST API (DJANGO) 的应用程序。 代码如下:
export class ForecastUnitService {
private path = 'forecastunit/';
private options;
constructor (private http: Http, private c:CentralService) {
this.options=this.c.createOptions();
}
getForecastUnits(): Observable<ForecastUnit[]> {
return this.http.get(this.c.createURL(this.path),this.options)
.map(this.extractData)
.catch(this.handleError);
}
...
}
我添加了包含授权标头的选项,但我仍然得到 403 禁止。但是,当我尝试使用 cUrl 或 Postman 或大摇大摆地进行通话时,我得到了同样的结果。 所以首先,标题不正确,但是当我记录选项时,我得到:
{"method":null,"headers":{"Authorization":["**Correct Token**"],"Content-Type":["application/json"]},"body":null,"url":null,"withCredentials":null,"responseType":null}
所以这不是问题,当我查看 Chrome 的响应时,我看到以下内容:
{"detail":"Authentication credentials were not provided."}
所以再次没有凭据,但我真的通过了,出了什么问题?
【问题讨论】:
-
您传递的令牌的格式是什么?
-
基本 64,我猜
-
想知道你在Authorization中传递的token的示例格式
-
我通过“基本”+大小写代码
标签: django angular api get authorization