simple get angular4 error:预检响应

时间:2017-06-20 02:59:12

标签: angular rest get x-xsrf-token

一个简单的get angular4错误:预检响应中的Access-Control-Allow-Headers不允许请求头字段X-XSRF-TOKEN。

url: string = 'https://api.elasticemail.com/mailer/status/log?format=json&username=mymail@mail.com&api_key=my-key;

private readData() {
  this._http.get(this.url)
  .subscribe(
  data => this.extractData(data),
  err => this.handleError(err)
  );
}

private extractData(res: Response) {
  console.log("generate teste")
  let body = res.json();
  console.log(body);
  return body.data || {}; 
}

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

在Windows中,将此命令粘贴到运行窗口

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
this will open a new chrome browser which allow access to no 'access-control-allow-origin' header request.

参考

  1. Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?