能否有人帮我修改下面的代码:
client.ExecuteAsync(request, response => {
Console.WriteLine(response.Content);
});
基本上,我想使用上面的ExecuteAsync方法,但不想打印输出结果,而是将response.Content返回给调用者。
有没有简单的方法实现这个目标?
我尝试了下面的方法,但不起作用:
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); // used on every request
var response = client.ExecuteAsync(request, response => {
return response.data);
});
}
上面的代码来自https://github.com/restsharp/RestSharp。