JsHttpClient 1.0.3

HttpClient extension class, and the .Net Core version of the HttpHelper class.
Simple and flexible crawler base class library.
JsHttpClient类是 .Net Core 下的一个简单灵活的爬虫基础类库

There is a newer version of this package available.
See the version list below for details.
Install-Package JsHttpClient -Version 1.0.3
dotnet add package JsHttpClient --version 1.0.3
<PackageReference Include="JsHttpClient" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsHttpClient --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
private readonly IJsHttpClient _client;

    /// <summary>
    /// 实例化
    /// Add by Jason.Song(成长的小猪) on 2019/04/24
    /// </summary>
    /// <param name="client"></param>
    public TestController(IJsHttpClient client)
    {
        _client = client;
    }

    /// <summary>
    /// Asynchronous request test
    /// 异步请求测试
    /// Add by Jason.Song(成长的小猪) on 2019/04/24
    /// </summary>
    /// <returns></returns>
    [HttpGet("HttpAsync")]
    public async Task<IActionResult> HttpAsync()
    {
        const string urlString = "https://blog.csdn.net/jasonsong2008";
        var request = new JsHttpRequest {Uri = urlString};
        //request.Method = HttpMethod.Get;
        //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
        //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
        //request.Referer = "https://blog.csdn.net/";
        //request.Host = "blog.csdn.net";
        //request.Cookie = "";
        //request.Timeout = 30;
        //request.Add("Upgrade-Insecure-Requests", "1");

        var result = await _client.SendAsync(request);
        return Content(result.Html, "text/html; charset=utf-8");
    }

    /// <summary>
    /// Synchronous request test
    /// 同步请求测试
    /// Add by Jason.Song(成长的小猪) on 2019/04/24
    /// </summary>
    /// <returns></returns>
    [HttpGet("HttpSync")]
    public IActionResult HttpSync()
    {
        const string urlString = "https://blog.csdn.net/jasonsong2008";
        var request = new JsHttpRequest { Uri = urlString };
        //request.Method = HttpMethod.Get;
        //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
        //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
        //request.Referer = "https://blog.csdn.net/";
        //request.Host = "blog.csdn.net";
        //request.Cookie = "";
        //request.Timeout = 30;
        //request.Add("Upgrade-Insecure-Requests", "1");

        var result = _client.Send(request);
        return Content(result.Html, "text/html; charset=utf-8");
    }
}

[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
private readonly IJsHttpClient _client;

    /// <summary>
    /// 实例化
    /// Add by Jason.Song(成长的小猪) on 2019/04/24
    /// </summary>
    /// <param name="client"></param>
    public TestController(IJsHttpClient client)
    {
        _client = client;
    }

    /// <summary>
    /// Asynchronous request test
    /// 异步请求测试
    /// Add by Jason.Song(成长的小猪) on 2019/04/24
    /// </summary>
    /// <returns></returns>
    [HttpGet("HttpAsync")]
    public async Task<IActionResult> HttpAsync()
    {
        const string urlString = "https://blog.csdn.net/jasonsong2008";
        var request = new JsHttpRequest {Uri = urlString};
        //request.Method = HttpMethod.Get;
        //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
        //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
        //request.Referer = "https://blog.csdn.net/";
        //request.Host = "blog.csdn.net";
        //request.Cookie = "";
        //request.Timeout = 30;
        //request.Add("Upgrade-Insecure-Requests", "1");

        var result = await _client.SendAsync(request);
        return Content(result.Html, "text/html; charset=utf-8");
    }

    /// <summary>
    /// Synchronous request test
    /// 同步请求测试
    /// Add by Jason.Song(成长的小猪) on 2019/04/24
    /// </summary>
    /// <returns></returns>
    [HttpGet("HttpSync")]
    public IActionResult HttpSync()
    {
        const string urlString = "https://blog.csdn.net/jasonsong2008";
        var request = new JsHttpRequest { Uri = urlString };
        //request.Method = HttpMethod.Get;
        //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
        //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
        //request.Referer = "https://blog.csdn.net/";
        //request.Host = "blog.csdn.net";
        //request.Cookie = "";
        //request.Timeout = 30;
        //request.Add("Upgrade-Insecure-Requests", "1");

        var result = _client.Send(request);
        return Content(result.Html, "text/html; charset=utf-8");
    }
}

Release Notes

const string urlString = "https://blog.csdn.net/jasonsong2008";
var request = new JsHttpRequest {Uri = urlString};
//request.Method = HttpMethod.Get;
//request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
//request.Referer = "https://blog.csdn.net/";
//request.Host = "blog.csdn.net";
//request.Cookie = "";
//request.Timeout = 30;
//request.Add("Upgrade-Insecure-Requests", "1");

var result = await _client.SendAsync(request);
return Content(result.Html, "text/html; charset=utf-8");

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.5 84 8/1/2019
1.0.4 162 4/24/2019
1.0.3 170 4/24/2019
1.0.2 163 4/24/2019
1.0.1 175 4/24/2019
1.0.0 186 4/23/2019