【发布时间】:2019-02-02 11:28:23
【问题描述】:
我的服务中定义了以下获取请求:
createAuthorizationHeader(user, pass) {
let headers: HttpHeaders = new HttpHeaders;
headers = headers.append('Accept', 'application/json, text/plain, */*');
headers = headers.append('Authorization', 'Basic ' + btoa(user + ':' + pass));
headers = headers.append('Content-Type', 'application/json; charset=utf-8');
console.log(headers);
return this.http.get(this._loginUrl, {
headers: headers
});
}
结果是:
OPTIONS https://localhost:8443/delivery/all 401 ()
Failed to load https://localhost:8443/delivery/all: Response for preflight does not have HTTP ok status.
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
我也用 Postman 发出了同样的发帖请求,但一切正常,所以本地服务器正常工作。
我不知道我的请求做错了什么。
【问题讨论】:
-
Nit: application/json 没有字符集参数