Ms_ Dev

Ms_ Dev

  • NA
  • 236
  • 92.1k

WebClient is giving exception

Apr 26 2017 12:38 AM
Hi,
 
WebClient is giving exception. It is not able to get the data in ResultInCSV. 
  1. try  
  2.             {  
  3.                 string ServiceURL = $"http://finance.yahoo.com/d/quotes.csv?s={symbol}&f=sl1d1nd";  
  4.                 string ResultInCSV;  
  5.                 using (WebClient client = new WebClient())  
  6.                 {  
  7.                     ResultInCSV = await client.DownloadStringTaskAsync(ServiceURL).ConfigureAwait(false);  
  8.                 }  
  9.                 var FirstLine = ResultInCSV.Split('\n')[0];  
  10.                 var Price = FirstLine.Split(',')[1];  
  11.                 if (Price != null && Price.Length >= 0)  
  12.                 {  
  13.                     double result;  
  14.                     if (double.TryParse(Price, out result))  
  15.                     {  
  16.                         return result;  
  17.                     }  
  18.                 }  
  19.                 return null;  
  20.             }  
  21.             catch (WebException ex)  
  22.             {  
  23.                 throw ex.InnerException;  
  24.             }  
  25.         }  
 Please help to get the data.
 
Thanks, 

Answers (9)