我正在嘗試使用Aurelia HttpClient在不同域(和身份驗證)上調用TagniFi API。相關的代碼是:Aurelia帶身份驗證的HttpClient
return this._httpClient.createRequest(uri)
.asGet()
.withCredentials(true)
.withHeader('Access-Control-Allow-Origin', 'localhost:9000')
.withHeader('Authorization', 'Basic <my-key>')
.send();
我收到來自API狀態200,但我得到了以下錯誤:
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:9000 ' is >therefore not allowed access. The credentials mode of an XMLHttpRequest >is controlled by the withCredentials attribute.
我不知道這是我的方式錯誤撥打電話或Aurelia中的錯誤。任何幫助表示讚賞。謝謝。
謝謝瓦倫丁,感謝您的回覆。所以,如果我理解正確,問題是我所調用的目標服務器未配置爲返回Access-Control-Allow-Origin標頭。換句話說,這不是我的代碼中的錯誤,而是服務器上的配置錯誤?如果這是我的代碼中的錯誤,請告訴我,如果您有建議的修復程序。謝謝。 – sevenshadow