我需要使用基本身份驗證進行http獲取請求,但我不知道如何。我正在使用ionic2,角色爲& typescript。 我的代碼:如何在Ionic內的http獲取請求中使用useBasicAuth?
this.http.get("http://address")
.map(res => res.json())
.subscribe(data =>{
console.log(data);
});
從離子文檔我看到我需要什麼,但我是新來的這些技術,我不能夠使用它:useBasicAuth(username, password)
我已經嘗試了這些解決方案,但它沒有工作:Angular 2- Http POST request parameters
編輯
我一直在努力之下
012碼let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic xxxxxxx=');
let options = new RequestOptions({ headers: headers });
this.http.get("http://VLCwebServerAddress",options)
甚至
this.http.get("http://VLCwebServerAddress",headers)
如果第二個參數是頭我得到的迴應401,所以驗證失敗。
如果第二個參數是選項我得到Response for preflight has invalid HTTP status code 501
其中I've read它與服務器端的CORS有關。
我「找不到getUserByName」如果我嘗試你的代碼。 我想知道如何使用文檔中定義的「getBasicAuthHeader(username,password)」,但沒有使用示例。 –
你對基本編程有什麼想法嗎?我寫的代碼需要保持服務。 –
我很容易被卡住......不過,我想我已經理解了你的代碼,並試圖按照你在編輯中看到的方式來實現。但仍然沒有成功。日Thnx。 –