private void button1_Click_1(object sender, EventArgs e)
try
{
ConnectionId.HostName = "host2.dnswind.com";
Uri sUrl =new Uri("http://www.chaton.dilipdotnet.com");
MyWebReq = (System.Net.HttpWebRequest)WebRequest.Create(sUrl);
MyWebRes = (System.Net.HttpWebResponse)MyWebReq.GetResponse();
sStream = MyWebRes.GetResponseStream();
string reader = new StreamReader(sStream).ReadToEnd();
//if (MyWebRes.StatusCode == HttpStatusCode.OK)
{
WebClient client = new WebClient();
Stream oStream = MyWebRes.GetResponseStream();
StreamReader oReader = new StreamReader(oStream);
string sResult = oReader.ReadToEnd();
if (sUrl.AbsoluteUri.ToString()=true)//here i want to check
{
MessageBox.Show("connection online");
}
else
{
MessageBox.Show("Connection offline");
}
}
}
catch (Exception ex)
{
//Url not valid
MessageBox.Show("Sorry you have typed wrong", ex.Message);
}
}
我想检查用户是否输入了它在线的 url,否则为离线状态,例如当我输入url时,在 winforms 中单击按钮,如果我不输入,它会显示离线。