日期:2013-09-11  浏览次数:20462 次

写了两个测试了一下,自己看看吧

public void GetResponse()
        {
            StringBuilder strSource = new StringBuilder();
            try
            {
                //WebRequest Wreq = WebRequest.Create("http://www.dev-club.com");
                //WebResponse Wresp = Wreq.GetResponse();

                Uri myUri = new Uri(this.l_strPageAddress);
                HttpWebResponse resp;
                HttpWebRequest req =
                    (HttpWebRequest)WebRequest.Create(myUri);
                resp = (HttpWebResponse)req.GetResponse();


                StreamReader sr = new StreamReader(resp.GetResponseStream(),Encoding.Default);
                string strTemp = "";

                while((strTemp = sr.ReadLine()) != null)
                {
                    strSource.Append(strTemp + "\r\n");
                }

                sr.Close();
            }
            catch(WebException WebExcp)
            {
                strSource.Append(WebExcp.Message);
            }
            this.form.AddMessage(strSource.ToString());
        }

        public void Socket_GetResponse()
        {
            

                IPHostEntry ipinfo    = Dns.Resolve(l_strServerAddress);
                IPAddress ip        = ipinfo.AddressList[0];
                IPEndPoint rip        = new IPEndPoint(ip,80);    

                s = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolTyp