【发布时间】:2022-01-19 18:23:03
【问题描述】:
我正在尝试将我的 Flutter 应用程序连接到我的 .net 核心应用程序中的集线器。
这就是我正在尝试的:
// Connection to the signalr Hub
_connectToHub() async {
// The location of the SignalR Server.
final serverUrl = "https://192.168.1.65:5001/notification";
// Creates the connection by using the HubConnectionBuilder.
final hubConnection = HubConnectionBuilder().withUrl(serverUrl,
options: new HttpConnectionOptions(accessTokenFactory: () async {return await FlutterSession().get("token");}))
.build();
await hubConnection.start().then((value){print("CONNECTED TO HOST HUB");}).onError((error, stackTrace){
print(stackTrace);
print(error);
});
hubConnection.on("simo", _invokedSimo);
// When the connection is closed, print out a message to the console.
hubConnection.onclose( (error) => print("Connection Closed"));
}
这是堆栈跟踪:
I/flutter (15069): #0 HttpConnection._startInternal (包:signalr_client/http_connection.dart:255:7) I/flutter(15069): 我/颤振(15069):#1
HubConnection.start (package:signalr_client/hub_connection.dart:103:5) I/颤动 (15069): I/颤动 (15069): #2
FutureExtensions.onError。 (dart:async/future.dart) I/颤动(15069): I/颤动(15069): FormatException:无效的 HTTP 标头字段名称:“Bearer eyJhbGciOiJ..
经过一点研究,这是包代码中断的地方:
final response = await _httpClient.post(negotiateUrl, options: options);
感谢您的帮助
【问题讨论】:
标签: .net flutter signalr webapi