Link to home
Start Free TrialLog in
Avatar of mikha
mikhaFlag for United States of America

asked on

web request in C#

say I am making a web request from my controller to another third party site to get some data.
sample below, example contrived for this question.

The third party site may be down and not return data. in such case, I would like to make couple of more tries and error out if it doesn't succeed at all.

Question - what's the best way to do this. so that if there is no response data in the first call , I try it say , two more times and
then error out.

     var webClient = new WebClient(); 
     var response = webClient.DownloadString("http://xyz.com/content); 

      if(response != null){
            //do something 
      }
      else {
             //error couldn't retrieve data
      }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dustin Saunders
No Points:

Agree, a loop would do it.  As commented, would suggest a sleep timer but you may also want to add some interaction on the front end (loading modal for example) so users aren't clicking around while you process attempts.