我開始學習如何在我的應用中使用Firebase。我按照角網站的指令,並設置片段像中的index.html:HTTP請求:PUT 401(未授權)
<!-- The codes to add firebase -->
<script src="https://www.gstatic.com/firebasejs/3.2.0/firebase.js"></script>
<!-- The core firebase client (required) -->
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script>
<!-- firebase-auth - Firebase Authentication (optional) -->
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
<!-- firebase-database - The Firebase Realtime Database (optional) -->
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
<script>
var config = {
apiKey: ...,
authDomain: ...,
databaseURL: "https://...",
storageBucket: "...",
};
firebase.initializeApp(config);
</script>
然後我嘗試使用HTTP請求,把數據,如:
submitForm(personalInfo: PersonalInfo, educationsInfo: Education[], experiencesInfo: Experience[]): Observable<string>{
let body = JSON.stringify({personalInfo, educationsInfo, experiencesInfo});
let headers = new Headers({'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers});
console.log(body);
let url = this.firebaseUrl + 'apply-form.json';
return this.http.put(url, body)
.map((response) => {
return response;
})
.catch(this.handleError);
}
但是,我得到了以下錯誤:
PUT https://XXX.firebaseio.com/apply-form.json 401 (Unauthorized)
我不知道是什麼問題。我是使用Firebase的新人,真的需要有人來幫助我。謝謝!
謝謝你的迴應。我認爲這可能是權威問題,但我沒有如何解決它。它在我更改安全規則後生效。但我會聽取您的建議,嘗試使用Firebase SDK。非常感謝 :) – gogopower