我在使用请求连接到 Angular2 组件中的 Neo4j 时遇到了 CORS 问题:
Response to preflight request doesn't pass access control check. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8080' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute
如何使用请求(Typescript)设置
withCredentials: false
?我假设这将解决问题。但是请求 ts 文件没有在其 withCredentials
对象中列出 CoreOptions
。 Neo4j-Typescript 包也没有在它的 Typescript 定义中包含它。 最佳答案
你可以通过扩展 BrowserXhr
类来做到这一点:
@Injectable()
export class CustomBrowserXhr extends BrowserXhr {
constructor() {}
build(): any {
let xhr = super.build();
xhr.withCredentials = false;
return <any>(xhr);
}
}
并使用扩展覆盖
BrowserXhr
提供程序:bootstrap(AppComponent, [
HTTP_PROVIDERS,
provide(BrowserXhr, { useClass: CustomBrowserXhr })
]);
关于neo4j - 请求选项 "withCredentials"- Angular2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36677794/