HTTPHelper

Posted jianhongtang2016

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTTPHelper相关的知识,希望对你有一定的参考价值。

 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的主要内容,如果未能解决你的问题,请参考以下文章

抓取百万知乎用户信息之HttpHelper的迭代之路

HttpHelper工具类

在模块之间传递变量[重复]

HttpHelper

csharp HttpHelper类

csharp HttpHelper类