protected void GetHtml() { string url = "http://www.baidu.com/"; HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url); //设置请求的url wRequest.Method = "Post"; wRequest.ContentType = "application/x-www-form-urlencoded"; wRequest.Timeout = 1000*60; byte[] charbyte = System.Text.Encoding.Default.GetBytes(url); //格式化参数 wRequest.ContentLength = charbyte.Length; StreamWriter sw = new StreamWriter(wRequest.GetRequestStream()); //字节流 try { sw.Write(url); }catch(Exception ex ){ }finally { sw.Close(); } StreamReader sr = new StreamReader(wRequest.GetResponse().GetResponseStream()); //开始接受服务器回传 string responseData = sr.ReadToEnd(); backResponse.InnerText = responseData; //得到结果 }
来给结果上个图,有图有真相:
也许你说,这么一大堆乱码,看着就头疼,怎么处理呢?下篇我们讲学习正则表达式,谢谢!