【发布时间】:2018-05-12 14:30:27
【问题描述】:
我有一个在 http://localhost:4200 运行的 Angular 应用程序和一个在 http://localhost:8000 运行的 Lumen API。
我正在使用 barryvdh/laravel-cors,我的所有 POSTS 请求都返回“请求的资源上没有 'Access-Control-Allow-Origin' 标头。”
有什么线索吗?我的 Angular 数据库服务:
@Injectable()
export class DatabaseService {
constructor(private http: Http) { }
get(url: string) {
return this.http.get("http://localhost:8000/" + url)
.map(response => response.json());
}
post(url: string, data) {
return this.http.post("http://localhost:8000/"+ url, data)
.map(response => response.json());
}
}
所有 GET 请求都能正常工作。
【问题讨论】:
-
你解决了这个问题吗?因为我遇到了同样的问题。
-
@Shivam 在 localhost 我刚刚使用了一个名为 CORS 的 Chrome 扩展程序,它解决了这个问题。