我使用角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