HttpWebRequest请求url返回数据

HttpWebRequest httpReq = (HttpWebRequest)HttpWebRequest.Create("http://www.baidu.com"); 创建request请求 httpReq.Method = "get"; 设置请求方式 HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse(); 返回response数据 Stream myRequestStream = httpRes.GetResponseStream(); 取得内容 StreamReader myStreamRead = new StreamReader(myRequestStream, Encoding.Default); 读取流 StringBuilder strdata = new StringBuilder(); while (myStreamRead.Peek() != -1) 转到下一行 { strdata.Append(myStreamRead.ReadLine() + "/r/n"); } myStreamRead.Close(); myRequestStream.Close();

你可能感兴趣的:(HttpWebRequest请求url返回数据)