小编Kal*_*nJa的帖子

预检的响应在角度中没有HTTP ok状态

我在我的服务中定义了以下get请求:

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
    });
}
Run Code Online (Sandbox Code Playgroud)

结果是:

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, …}
Run Code Online (Sandbox Code Playgroud)

我也和Postman做了相同的帖子请求,但一切正常,所以本地服务器工作.

我无法弄清楚我的要求是怎么回事.

http cors angular

21
推荐指数
4
解决办法
4万
查看次数

标签 统计

angular ×1

cors ×1

http ×1