【问题标题】:Angular4 - Services - Response for preflight has invalid HTTP status code 403Angular4 - 服务 - 预检响应具有无效的 HTTP 状态代码 403
【发布时间】:2018-05-29 21:38:57
【问题描述】:

我正在尝试从服务器获取数据,但出现以下错误:

预检响应包含无效的 HTTP 状态代码 403。

getGroupsResponse(): 
Observable<IMainPageGroupResponseModel> {
    this.dataUrl='http://localhost:8080/myApp/v1/Lookup/groups/list/19763';

    const headers = new Headers({ 'Content-Type': 'application/json' });
    headers.append('Access-Control-Allow-Origin', '*');
    const options = new RequestOptions({ headers:headers });

    return this.http.get(this.dataUrl,options)
            .map((response:Response) => <IMainPageGroupResponseModel>response.json())
            .catch(this.handleError);
}

我已经安装了 chrome 的核心插件,我的应用在 4300 端口,服务器端代码在 8080 端口本地运行。

我不明白为什么会出现此错误

【问题讨论】:

    标签: angular


    【解决方案1】:

    问题在于您的服务器端代码。为了从后端请求数据,您需要实现 CORS 标头。具体来说,您需要允许来自您的前端,并且您还需要允许您支持的方法。

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 2016-02-08
      • 2018-04-05
      • 2018-09-22
      • 2018-09-30
      • 2018-01-25
      • 2016-12-26
      • 2018-04-11
      • 2016-01-18
      相关资源
      最近更新 更多