我使用角2开发的应用程序,我发现下面的错误,当我尝试调用API:否“访问控制允许来源”标头角2,但卷曲工作正常
XMLHttpRequest无法加载http://localhost:9090/conf。对预检请求的响应不会通过访问控制检查:请求的资源上不存在“访问控制 - 允许来源”标头。因此'Origin'http://localhost:5555'不允许访问。
在这里,有我的电话的两个例子:
import { Http, Response } from '@angular/http';
// ...
@Injectable()
export class ConfService {
// ...
getConf(): Observable<string[]> {
return this.http.get(
'http:localhost:9090/conf?id=1',
{
headers: {
'Accept': 'application/json;charset=UTF-8'
}
}
)
.map((res: Response) => res.json())
.catch(this.handleError);
}
setConf(conf: any[]): Observable<string[]> {
return this.http.get(
'http:localhost:9090/conf?id=1',
conf,
{
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
}
)
.map((res: Response) => res.json())
.catch(this.handleError);
}
}
然而,当我使用卷曲它的作品!
$ curl -XPUT 'localhost:9090/configuration?id=1' \
> -H 'Content-Type: application/json'
> -d '{"conf":1234}'
Success!
$ curl -XGET 'localhost:9090/conf?id=1'
{"conf":1234}
这里发生了什么事?
谢谢
https://chrome.google.com/webstore/detail/cors-toggle/omcncfnpmcabckcddookmnajignpffnh – Lonely