Poilkj19.NetModularity.Http 9.0.1

dotnet add package Poilkj19.NetModularity.Http --version 9.0.1                
NuGet\Install-Package Poilkj19.NetModularity.Http -Version 9.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Poilkj19.NetModularity.Http" Version="9.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Poilkj19.NetModularity.Http --version 9.0.1                
#r "nuget: Poilkj19.NetModularity.Http, 9.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Poilkj19.NetModularity.Http as a Cake Addin
#addin nuget:?package=Poilkj19.NetModularity.Http&version=9.0.1

// Install Poilkj19.NetModularity.Http as a Cake Tool
#tool nuget:?package=Poilkj19.NetModularity.Http&version=9.0.1                

Http 请求模块

1. 介绍

基于 HttpClient 进行的扩展原汁原味的 HttpClient,支持请求重试、请求超时、请求日志、请求缓存、请求拦截等功能。

// 使用示例
clientFactory.CreateClient()
        .Send<TResponse>(req =>
        {
            req.Url(request.GetRequestUrl()).Verb(request.GetRequestMethod());
            var queryParams = new Dictionary<string, object> { { "access_token", GetAccessToken(devConfig) } };
            if (req.Method == HttpMethod.Get)
            {
                foreach (var (key, val) in request.BuildRequestParameters()) queryParams.Add(key, val);
            }
            else
            {
                // 获取上传文件的参数
                var fileParams = request.GetFileParameters();
                if (fileParams == null)
                {
                    // 直接JSON请求体
                    req.JsonBody(request.BuildRequestParameters(), null);
                }
                else
                {
                    // 以form提交方式
                    var boundary = DateTime.Now.Ticks.ToString("X");
                    req.Form(form =>
                    {
                        // 请求参数
                        foreach (var (key, val) in request.BuildRequestParameters())
                            form.Add(new StringContent(val.ToString(), encoding: null), $"\"{key}\"");
                        // 文件参数
                        foreach (var (key, val) in fileParams)
                            form.Add(new ByteArrayContent(File.ReadAllBytes(val.FullName)), key, val.Name);
                    }, boundary);
                }
            }

            req.Query(queryParams);
            req.OnResponse((res, content, data) =>
            {
                if (data.ErrCode == (int)DingErrorCode.Success) return;
                if (request.OnError != null)
                {
                    request.OnError(data);
                    return;
                }

                if (request.IfNotSuccessThrow) throw new Exception($"[钉钉] {data.ErrMsg}");
            });
        })
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on Poilkj19.NetModularity.Http:

Package Downloads
Poilkj19.NetModularity.GuanData

观远SDK

Poilkj19.NetModularity.Juhe

聚合SDK

Poilkj19.NetModularity.Moka

摩卡SDK

Poilkj19.NetModularity.KeyFunc

企云方SDK

Poilkj19.NetModularity.DouDian

抖店SDK

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.1 169 2/7/2025
8.0.1 201 2/7/2025
7.0.1 213 2/7/2025