我在CORS上有错误:
“XMLHttpRequest无法加载http://graphql-swapi.parseapp.com/ . 对预检请求的响应未通过访问控制检查:请求的资源上没有'Access-Control-Allow-Origin'标头 . 来源'因此,http:// localhost:3000'不允许访问 . 响应的HTTP状态代码为405.“
我调用服务方法时出错 .
Code Snippet:
let headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
headers.append('Access-Control-Allow-Methods', 'POST');
headers.append('Access-Control-Allow-Headers', 'Content-Type');
//console.log(headers);
return this._http.post(apiUrl, { query: query, vars: '{}' }, { headers: headers })
.map(res => res.json().data.planets);
当我在浏览器中禁用CORS时,我得到:
XMLHttpRequest无法加载xxx . 预检的响应具有无效的HTTP状态代码405错误 .
查询和代码肯定是正确的 .
1 回答
Look that up:
Look that up:
据推测,您的服务器端代码可以设置为将CORS标头添加到POST请求的响应中,但您还没有设置它来处理OPTIONS请求 .