字典作为SignalR Android Client中的查询字符串参数

时间:2014-08-20 19:54:04

标签: android signalr

C#代码

var querystringData = new Dictionary<string, string>();
querystringData.Add("UserName", LocalSettings.UserName);
querystringData.Add("LoginId", LocalSettings.LoginId);
hubConnection = new HubConnection("http://...", querystringData);

如何在Android中将Dictionary作为queryString传递

Platform.loadPlatformComponent( new AndroidPlatformComponent() );
String host = "http://....;
String qs = ""; 

//而不是String我想传递List / Dictionary

HubConnection connection = new HubConnection(host, qs, true, new ConsoleLogger());
HubProxy hub = connection.createHubProxy("calculatorHub");

http://whathecode.wordpress.com/2014/03/20/getting-started-with-the-java-signalr-sdk/为基础

2 个答案:

答案 0 :(得分:3)

C#客户端基本上将您传递的字典转为&#34;&amp; {key} = {value}&#34;对于每个KeyValuePair。所以你应该能够做同样的事情,并作为queryString传递给HubConnection ctor。

答案 1 :(得分:1)

这里我的代码完美无缺

String server = URL + "signalr";
        String CONNECTION_QUERYSTRING ="Bearer=" + BaseActivity.getToken(activity).getAccess_token();
        HubConnection connection = new HubConnection(server, CONNECTION_QUERYSTRING, false, new Logger() {
            @Override
            public void log(String message, LogLevel level) {
                System.out.println(message);
            }
        });