Monday, July 23, 2018

Ping a url without opening in browser

Ping a url without opening in browser



 private void BrowseUrl(string url)
        {
            try
            {
                HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(url);

                // *** Return the Response data
                HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();

                Encoding enc = Encoding.GetEncoding(1252);  // Windows-1252 or iso-
                if (loWebResponse.ContentEncoding.Length > 0)
                {
                    enc = Encoding.GetEncoding(loWebResponse.ContentEncoding);
                }

                StreamReader loResponseStream =
                    new StreamReader(loWebResponse.GetResponseStream(), enc);

                string response = loResponseStream.ReadToEnd();

                if (response.Length != 0)
                {
                   // You can write this response to some textbox here also
                }

                loResponseStream.Close();
                loWebResponse.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


visit link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.