搂住又开了个帖子??
呵呵,再帖一次:
源代码中是否有无法找到网页
http://dotnet.aspx.cc/ShowDetail.aspx?id=0A6660CE-4138-41EF-B882-15DB65564709

解决方案 »

  1.   

    用ping把,不过对方要是装防火墙不响应就没办法了。代码如下:
    private static string CmdPing(string strIp)
    {
    Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = true;
    string pingrst;
    p.Start();
    p.StandardInput.WriteLine("ping -n 1 "+strIp);
    p.StandardInput.WriteLine("exit");
    string strRst = p.StandardOutput.ReadToEnd();
    if(strRst.IndexOf("(0% loss)")!=-1)
    pingrst = "连接";
    else if( strRst.IndexOf("Destination host unreachable.")!=-1)
    pingrst = "无法到达目的主机";
    else if(strRst.IndexOf("Request timed out.")!=-1)
    pingrst = "超时";
    else if(strRst.IndexOf("Unknown host")!=-1)
    pingrst = "无法解析主机";
    else
    pingrst = strRst;
    p.Close();
    return pingrst; }
      

  2.   

    用socket连接 该服务器的80端口 ,发送 GET HTML/1.1
    接收收到的文字,分析里面的内容比如 是 有404错误, 就是文件没找到.
      

  3.   


    WebRequest myWebRequest=WebRequest.Create("一个无效链接的地址");
    myWebRequest.Timeout=5000;
    try
    {
    WebResponse myWebResponse=myWebRequest.GetResponse();
    Stream resStream = myWebResponse.GetResponseStream();
    StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
    this.Label1.Text = sr.ReadToEnd();
    resStream.Close(); 
    sr.Close();
    }
    catch(System.Net.WebException xx)
    {
    this.Label1.Text=xx.Message;
    }如果label标签显示:无效的地址404错误说明链接无效