我正在尝试使用 发出异步获取请求ExecuteAsync<T>
,但它从不响应。令我困惑的是,ExecuteAsync
同步方法Execute
和Execute<T>
.
这是我的代码:
var restClient = new RestClient("http://localhost:44268/api/");
var request = new RestRequest("jobs/{id}", Method.GET);
request.AddUrlSegment("id", "194");
// works
var req1 = restClient.Execute(request).Content;
// works
var req2 = restClient.Execute<Job>(request).Content;
// works
var req3 = restClient.ExecuteAsync(request, (restResponse) =>
{
var test = restResponse.Content;
Console.WriteLine(test);
});
var req4 = restClient.ExecuteAsync<Job>(request, (restResponse) =>
{
// this code is never reached
var test = restResponse.Content;
Console.WriteLine(test);
});
它成功地调用了 API,但它永远不会回调。为什么?难道我做错了什么?