小编jos*_*lie的帖子

我应该如何在Windows Phone 7上使用RestSharp实现ExecuteAsync?

我正在尝试使用RestSharp GitHub wiki上的文档来实现对我的REST API服务的调用,但我特别遇到了ExecuteAsync方法的问题.

目前我的代码对于API类来说是这样的:

public class HarooApi
{
    const string BaseUrl = "https://domain.here";

    readonly string _accountSid;
    readonly string _secretKey;

    public HarooApi(string accountSid, string secretKey)
    {
        _accountSid = accountSid;
        _secretKey = secretKey;
    }

    public T Execute<T>(RestRequest request) where T : new()
    {
        var client = new RestClient();
        client.BaseUrl = BaseUrl;
        client.Authenticator = new HttpBasicAuthenticator(_accountSid, _secretKey);
        request.AddParameter("AccountSid", _accountSid, ParameterType.UrlSegment);
        client.ExecuteAsync<T>(request, (response) =>
        {
            return response.Data;
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道这稍微偏离了GitHub页面上的内容,但我在WP7中使用它,并且相信该示例是针对C#的,因此使用了ExecuteAsync方法.

我的问题是ExecuteAsync命令应该包含什么.我不能用,return response.Data因为我被警告:

'System.Action<RestSharp.RestResponse<T>,RestSharp.RestRequestAsyncHandle>' returns void, a return keyword …
Run Code Online (Sandbox Code Playgroud)

c# api rest windows-phone-7 restsharp

28
推荐指数
4
解决办法
5万
查看次数

我应该通过移动应用程序对Sorcery gem使用哪种身份验证方法?

考虑到我想在各种移动平台(Android,iOS, WP7等)?

提前致谢。

编辑 我暂时决定要做的事情如下:

  1. 使用Sorcery登录:http_basic_auth到Web服务的用户
  2. 如果登录成功,则生成一个基于时间的令牌和该令牌的到期时间
  3. 将令牌传递回客户端
  4. 客户端(Android,iOS,WP7等)随每个请求将令牌传递给服务。
  5. 然后,Web服务使用auto_loginSorcery方法对用户进行身份验证,然后将资源传递回客户端

另外,由于它是一个电子商务站点,因此还可以提高安全性,因此它将通过SSL运行。我最终将计划实现某种OTP / OAuth方法,但将在测试后执行。我希望这对寻求简单的Rails移动身份验证的其他人有所帮助。谢谢您的帮助。

android ruby-on-rails windows-phone-7 ios sorcery

5
推荐指数
1
解决办法
903
查看次数

标签 统计

windows-phone-7 ×2

android ×1

api ×1

c# ×1

ios ×1

rest ×1

restsharp ×1

ruby-on-rails ×1

sorcery ×1