How do you detect your given URL (ULL) under WinForm, is it accessible? (Netizen post, for reference only)

xiaoxiao2021-03-05  28

That is to say, I want to monitor a website, I want to write: I have access to the time, see if it is good!

WebRequest myWebRequest = WebRequest.Create ( "a broken link address"); myWebRequest.Timeout = 5000; try {WebResponse myWebResponse = myWebRequest.GetResponse (); Stream resStream = myWebResponse.GetResponseStream (); StreamReader sr = new StreamReader (resStream, System.Text.Encoding.default); this.label1.text = sr.readToend (); resstream.close (); sr.close ();} catch (system.net.webexception xx) {this.label1.text = XX.Message;}

If the Label tag is displayed: invalid address 404 Error Description Link invalid (if a Label tag display web source code)

============================================================================================================================================================================================================= =======================================================================================================================================================

WebRequest myWebRequest = WebRequest.Create (@ "address to be tested"); myWebRequest.Timeout = -1; try {WebResponse webResponse = webRequest.GetResponse (); Stream webStream = webResponse.GetResponseStream (); webStream.Close ();

} catch (system.net.webexception e) {// If it is a response to the web server, the error response, output error type and its description IF (E.Status == WebExceptionStatus.Protocoler) {Console.writeline (" Status Code 222: {0} ((httpwebresponse) E.RESPONSE) .StatusCode; console.writeline ("Status Description 333: {0}", (httponse) E.RESPONSE) .StatusDescription; // console .WriteLine (E.Message "Timeout");

转载请注明原文地址:https://www.9cbs.com/read-33890.html

New Post(0)