I have a function that returns the site server when entering the URL for the site:
private string GetWebServer() { string server = string.Empty; //get URL string url = txtURL.Text.Trim().ToLower(); if (!url.StartsWith("http://") && !url.StartsWith("https://")) url = "http://" + url; HttpWebRequest request = null; HttpWebResponse response = null; try { request = WebRequest.Create(url) as HttpWebRequest; response = request.GetResponse() as HttpWebResponse; server = response.Headers["Server"]; } catch (WebException wex) { server = "Unknown"; } finally { if (response != null) { response.Close(); } } return server; }
I would also like to get the site server from the IP address instead of the site URL. But if I specify the IP address, I get the error "Invalid URI: URI format could not be determined." when calling WebRequest.Create (url).
Does anyone know how I can change this to accomplish what I want?
source share