0

我想同步调用一个restful api。我想知道如何同步访问服务 api?是否可以同步调用api?

4

1 回答 1

1

您的方案不需要同步调用。您所需要的只是处理传入的响应,而异步模型可以完美地做到这一点。

假设您正在使用 WebClient(很容易适应任何场景):

WebClient client = new WebClient();
client.DownloadStringCompleted += (s,e) =>
{
     if (e.Result == "Paid")
        LoadingScreen.Visibility = Visibility.Collapsed;
};
client.DownloadStringAsync(new Uri("http://somerestapi.out.there"));
LoadingScreen.Visibility = Visibility.Visible;
于 2012-07-17T16:45:31.083 回答