c# - Check if connect to remote server by Webclient -
i want check if project can connect remote server webclient in asp.net c# , something.
here code
webclient webclient = new webclient(); webclient.credentials = new system.net.networkcredential(username, password); if (webclient.openread(url83).isconnected) // here, want check { xmltextreader reader1 = new xmltextreader(webclient.openread(url83)); reader1.whitespacehandling = whitespacehandling.none; //do }
as described here best way check internet connectivity might like
try { using (var client = new webclient()) using (var stream = client.openread(url83)) { xmltextreader reader1 = new xmltextreader(stream); reader1.whitespacehandling = whitespacehandling.none; //do } } catch (webexception ex) { // occurs when error occur while reading network stream }
Comments
Post a Comment