我利用Socket下载网页存储到本地,建立连接后Send命令字串为:“GET / HTTP/1.1\r\nHost: " + Server + \r\nConnection: Close\r\n\r\n" , Server是网址比如www.163.com,可是这只是首页我怎么才能下载到子网页,我试了server改为比如news.163.com\5\erewergdfg1t24.html,但这个网页打不开。我想我是不懂字串:“GET / HTTP/1.1\r\nHost: " + Server + \r\nConnection: Close\r\n\r\n"的命令含义,有那位精通的告诉我怎么写这个命令字串???

解决方案 »

  1.   

    如何向远程主机提出页面请求?我想这只是Asp的问题吧?
    up
    up
    up
      

  2.   

    string server = "news.163.com";
    string path = "/5/erewergdfg1t24.html";
    string sendString = 
    "GET " + path + " HTTP/1.1\r\n" + 
    "Host: " + server + "\r\n" + 
    "Connection: Close\r\n\r\n";
      

  3.   

    用socket大才小用了
    用System.Net.WebClient或者HttpWebRequest和HttpWebResponse比较合适
      

  4.   

    public static string  GetHtml(string url)
    {
    HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(url);
    myHttpWebRequest.Accept=@"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";   
    myHttpWebRequest.UserAgent=@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607; .NET CLR 1.1.4322)";//ie欺骗


    try
    {
    HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
                   
    Stream streamResponse=myHttpWebResponse.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse,Encoding.Default);
    string htmlcode=streamRead.ReadToEnd();
    streamRead.Close();

    streamResponse.Close();
    myHttpWebResponse.Close();

    return htmlcode;//返回字符串 } catch(Exception e)
    {

    return "error";
    }
    }
      

  5.   

    上面那个函数 接受各url
    返回string
    设置ie欺骗和accept类型,
    设置 gb2312编码功能足够 你受的料