API在Postman中运行良好,但在角度不佳
我试图从API中获取数据,但收到了此消息has been blocked by CORS policy
,但是我添加了扩展名来传递问题,但还是如此。
export class ProductsService {
url = "http://demo.sylius.com/api/v1/products/";
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer SampleToken'
})
};
constructor(private http: HttpClient) { }
GetAllProducts() {
return this.http.get(this.url, this.httpOptions);
}
}
从原点“ http://demo.sylius.com/api/v1/products/”到“ http://localhost:4200”处对XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:预检请求不允许重定向
core.js:7187错误HttpErrorResponse {headers:HttpHeaders,status:0,statusText:“ Unknown Error”,url:“ http://demo.sylius.com/api/v1/products/”,ok:false,...}