我正在尝试使用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) 考虑到我想在各种移动平台(Android,iOS, WP7等)?
提前致谢。
编辑 我暂时决定要做的事情如下:
:http_basic_auth到Web服务的用户auto_loginSorcery方法对用户进行身份验证,然后将资源传递回客户端另外,由于它是一个电子商务站点,因此还可以提高安全性,因此它将通过SSL运行。我最终将计划实现某种OTP / OAuth方法,但将在测试后执行。我希望这对寻求简单的Rails移动身份验证的其他人有所帮助。谢谢您的帮助。