Invincible
Invincible

Reputation: 422

How to get a synchronous HTTP response

I want to call one restful api synchronously. I want to know how can I hit service api synchronously? Is it possible to call api synchronously?

Upvotes: 0

Views: 724

Answers (1)

Den
Den

Reputation: 16826

You do not need a synchronous call for your scenario. All you need is to handle the incoming response, and the asynchronous model does that perfectly.

Assuming that you are working with WebClient (easily adapted to any scenario):

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;

Upvotes: 1

Related Questions