我正在尝试使用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;
});
}
}
我知道这与GitHub页面上的稍有不同,但我将其用于WP7,并相信该示例是针对C#的,因此使用了ExecuteAsync方法。
我的问题是ExecuteAsync命令应该包含什么内容。我不能使用return response.Data
,因为我被警告:
'System.Action<RestSharp.RestResponse<T>,RestSharp.RestRequestAsyncHandle>' returns void, a return keyword must not be followed by an object expression
有没有人有任何关于如何解决这个问题的见解或一个可能会有所帮助的教程?
https://stackoverflow.com/questions/10153749
复制相似问题