【发布时间】:2019-10-22 18:23:40
【问题描述】:
我使用 Angular 作为前端,使用 Symfony 作为后端。
这是我尝试从后端获取数据的方式:
getTechnologies(): Observable<Itechnologies[]> {
return this.http.get<Itechnologies[]>('http://localhost/technologies');
}
这是尝试从后端发送数据的方法:
public function getTechnologies(Request $request) {
$technologies = $this->technologyService->getTechnologies($request->getContent());
return new Response(json_encode($technologies));
}
这是我得到的:
从 'http://localhost/technologies' 访问 XMLHttpRequest 来源“http://localhost:4200”已被 CORS 策略阻止:否 请求中存在“Access-Control-Allow-Origin”标头 资源。
我也用header('Access-Control-Allow-Origin: *'); 尝试过,但我得到了同样的错误。
如果它们都在本地主机上,为什么我会收到此错误?
【问题讨论】:
标签: angular symfony http-headers