Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C# Webclient class output

Tags:

c#

In C# console application , i need to capture the out "Internet cannot display the webpage", then i can put my check. If internet browser opens the url means internet connection is there, else connection down. I am using below code

    WebClient client = new WebClient();
        string value = client.DownloadString("http://foo.com");
        Console.WriteLine(value.Length);
        Console.WriteLine(value);
        Console.WriteLine("Press any key to continue");

        Console.ReadKey(true);

Please se the method to capture the output

like image 896
Sohail Avatar asked Aug 28 '26 22:08

Sohail


1 Answers

You have to get the status code from web client.

Based on the status code you can identify the state of the current connection.

Please refer the following code.

How to get status code from webclient?

like image 194
Jomy John Avatar answered Aug 30 '26 11:08

Jomy John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!