c# wince5.0 手持机开发中如何wifi连接成功后如何在程序中判断网络连接是否成功,并且和指定网站页面数据交换,谢谢。
public static bool IsWebAccessible()
{
HttpWebRequest hwrRequest;
HttpWebResponse hwrResponse;
string strUrl = @"http://www.baidu.com/";
bool bConnected = false;
try
{
hwrRequest = (HttpWebRequest)WebRequest.Create(strUrl);
hwrRequest.Timeout = 100;
hwrResponse = (HttpWebResponse)hwrRequest.GetResponse();
if (hwrResponse.StatusCode == HttpStatusCode.OK)
{
bConnected = true;
}
}
catch (WebException we)
{
bConnected = false;
}
catch (Exception ex)
{
bConnected = false;
}
finally
{
hwrRequest = null;
hwrResponse = null;
}
return bConnected;
}
private void button1_Click_1(object sender, EventArgs e)
{
if (IsWebAccessible())
{
MessageBox.Show("可用");
}
else {
MessageBox.Show("不可用");
}
}