0

I am using this C# code in LINQPad 6 (Free Edition) to download data from a webpage

void Main()
{

string a = "https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp";

WebClient w = new WebClient();

w.DownloadStringAsync(new Uri(a));

w.DownloadStringCompleted += (s,e) => { 
        string t = (string)e.Result;
        Console.WriteLine (t);
        };   

}

I am always getting the WebException - An error occurred while sending the request. The response ended prematurely. enter image description here

Can anyone please kindly point out my mistake. Awaiting your reply. Thank you.

Romeo
  • 57
  • 8
  • 1
    Did you read the docs for the `WebClient` class, particularly the *Remarks*: "We don't recommend that you use the `WebClient` class for new development. Instead, use the `System.Net.Http.HttpClient` class." Then learn how `async` and `await` work – Flydog57 Jun 16 '20 at 01:47
  • Thank you Flydog57 I will read them now. – Romeo Jun 16 '20 at 02:00

0 Answers0