5
我在離子2中使用庫ng2-signalr
。問題是我不知道如何設置授權標頭。我有搜索,但沒有找到任何示例。如何在ng2-signalr中設置授權標題?
我的代碼連接到服務器集線器。
let options: IConnectionOptions = { qs:{userId:1}, url: "http://192.168.0.211:44337"};
console.log("Stage 1");
//Header for 'this.singalR.connect'
this.signalR.connect(options)
.then((connection) => {
console.log("Client Id: " + connection.id);
}, (err) => {
console.log("SignalR Error: " + JSON.stringify(err));
});
如何設置下面的標題?
var headers = new Headers({
'Content-Type': "application/json",
"Authorization": 'Bearer ' + accessToken //accessToken contain bearer value.
});
更新1
這裏的鏈接Query String Solution。解決方法是通過authorization token
在qs
中提及並進行相應處理。但我想設置在標題中,所以這個解決方案不適合我。還有一個原因,因爲我有另一個客戶端(Simple angularjs signalr),當我像下面那樣設置標題時,它可以正常工作。
$.signalR.ajaxDefaults.headers = { Authorization: //here set header};
注:執行授權相同的代碼工作正常,因爲我並不需要設置授權頭之前。
你嘗試在QS設置令牌? –
@suraj還沒有.oky我試過,但沒有任何意義,在查詢字符串'qs'中設置標題值。 –
https://stackoverflow.com/questions/21196266/signalr-authentication-with-javascript-client –