URLHelper

/// <summary>
        /// 请求url获取信息
        /// </summary>
        /// <param name="url">地址</param>
        /// <returns>url获取信息</returns>
        private static string GetHttpRequestString(string url)
        {
            // 设置返回值
            string htmlResult = string.Empty;

            try
            {
                // 请求url获取信息
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "Get";
                request.ContentType = "application/x-www-form-urlencoded ";

                // 获取响应
                WebResponse response = request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
                htmlResult = sr.ReadToEnd();

                // 关闭流释放资源
                sr.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                //LogUtil.Error("天气情况提取失败:" + ex.ToString());
            }

            return htmlResult;
        }

猜你喜欢

转载自www.cnblogs.com/MrZheng/p/8966286.html

相关文章