码迷,mamicode.com
首页 > Web开发 > 详细

HTTPHelper

时间:2018-08-04 11:46:59      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:url   .net   gb2312   stat   ons   default   har   stream   div   

 public class HTTPHelper
    {
        public static HttpClient Client { get; } = new HttpClient();
        public static string GetHTMLByURL(string url)
        {
            try
            {
                System.Net.WebRequest wRequest = System.Net.WebRequest.Create(url);
                wRequest.ContentType = "text/html; charset=gb2312";
                wRequest.Method = "get";
                wRequest.UseDefaultCredentials = true;
                // Get the response instance.
                var task = wRequest.GetResponseAsync();
                System.Net.WebResponse wResp = task.Result;
                System.IO.Stream respStream = wResp.GetResponseStream();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding("GB2312")))
                {
                    return reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("GetHTMLByURL Exception", ex,new { Url=url});
                return string.Empty;
            }
        }

      
    }

 

HTTPHelper

标签:url   .net   gb2312   stat   ons   default   har   stream   div   

原文地址:https://www.cnblogs.com/jianhongtang2016/p/9417264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!