alexmen

专注.net软件开发,项目管理体系PMBOK.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 /// <summary>
    /// 获取URL内容
    /// </summary>
    /// <param name="Url"></param>
    /// <returns></returns>
    public string HttpGet(string Url)
    {
        HttpWebRequest request = (HttpWebRequest )WebRequest.Create(Url);
        request.Method = "GET";
        request.ContentType = "text/html;charset=UTF-8" ;

        HttpWebResponse response = (HttpWebResponse )request.GetResponse();
        Stream myResponseStream = response.GetResponseStream();
        StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8" ));
        string retString = myStreamReader.ReadToEnd();
        myStreamReader.Close();
        myResponseStream.Close();

        return retString;
    }

 

posted on 2016-01-18 17:25  alexmen  阅读(249)  评论(0编辑  收藏  举报