请求未通过访问控制检查:否'Access-Control-Allow-Origin' [英] Request doesn't pass access control check: No 'Access-Control-Allow-Origin'
问题描述
我只是想从我的 http:// localhost:8080
但是收到此错误:
XMLHttpRequest无法加载 http://www.mocky.io/v2/5715f13a1100004d1187d9e1 。对预检请求的响应未通过访问控制检查:请求的资源上不存在Access-Control-Allow-Origin标头。因此,不允许访问 http:// localhost:8080 。
我的请求看起来像这样:
let headers = new Headers();
headers.append('Content-Type','application / json');
headers.append('Access-Control-Allow-Origin','*');
this.people = http.get('http://www.mocky.io/v2/5715f13a1100004d1187d9e1',{header:headers})
.map(response => response.json() );
实际上你应该设置标题 mocky.io中的Access-Control-Allow-Origin
。
只需点击切换到高级模式,您就会看到自定义标题输入。添加 Access-Control-Allow-Origin
并将 *
作为其值。然后创建你的mocky.io网址。它应该现在可以工作。
I am just trying to use mocky.io
from my http://localhost:8080
But getting this error:
XMLHttpRequest cannot load http://www.mocky.io/v2/5715f13a1100004d1187d9e1. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
My request looking like that:
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Origin', '*');
this.people = http.get('http://www.mocky.io/v2/5715f13a1100004d1187d9e1', { headers: headers })
.map(response => response.json());
Actually you should setup the header Access-Control-Allow-Origin
in mocky.io.
Just click on "Switch to Advanced mode" and you will see a "custom headers" input. Add Access-Control-Allow-Origin
and put *
as its value. Then create your mocky.io url. It should work now.
这篇关于请求未通过访问控制检查:否'Access-Control-Allow-Origin'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!