我正在用RestSharp
WP8 编写一个程序,确切地说是 LastFMSharp,但我必须将方法更新到ExecuteAsync
它的 WP。问题在于 Execute(request) 返回一个 RestResponse 之前,ExecuteAsync 返回一个 RestRequestAsyncHandle。我的方法需要 RestResponse。那么如何将它放入 var 响应中呢?请记住,结构是
RestSharp.RestClient.ExecuteAsync<T>(RestSharp.IRestRequest,System.Action<RestSharp.IRestResponse<T>,RestSharp.RestRequestAsyncHandle>)
谢谢您的帮助!
原来的:
public RestResponse<T> Execute<T>(RestRequest request) where T : new()
{
request.AddParameter("api_key", _apiKey);
var response = _restClient.Execute<T>(request);
RequestCount++;
DataCount += response.RawBytes.Length;
return response;
}
改变(不工作不知道应该是什么回调):
public RestResponse<T> Execute<T>(RestRequest request) where T : new()
{
request.AddParameter("api_key", _apiKey);
//var response =
_restClient.ExecuteAsync(request, response =>
{
callback(response.Content);
});
RequestCount++;
DataCount += response.RawBytes.Length;
return response;
}
回调初始化响应?我怎样才能做到这一点?