给一个网址如http://IP:8080/abc/index.jsp,请问用C#怎样实现检测它是否可连接?

解决方案 »

  1.   

    if (response.StatusCode == HttpStatusCode.NotFound)//404错误判断死链
      

  2.   

    用HttpWebRequest发送请求,然后用if (response.StatusCode == HttpStatusCode.NotFound)判断HttpWebRequest你可以上网搜搜他的用法 很多的,不过代码还是自己写好,孰能生巧
      

  3.   

     WebClient client = new WebClient();
                    client.Headers.Add("Content-Type", "text/html; charset=gb2312");
                    Stream data = client.OpenRead(url);
                    StreamReader reader = new StreamReader(data, Encoding.GetEncoding("gb2312"));
                    info = reader.ReadToEnd();
                    reader.Close();
                    data.Close();