Sage.Http 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sage.Http --version 1.0.0
                    
NuGet\Install-Package Sage.Http -Version 1.0.0
                    
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="Sage.Http" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sage.Http" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Sage.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sage.Http --version 1.0.0
                    
#r "nuget: Sage.Http, 1.0.0"
                    
#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.
#:package Sage.Http@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sage.Http&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Sage.Http&version=1.0.0
                    
Install as a Cake Tool

Sage.Http

简介

Sage.Http 是一个 HTTP 客户端封装库,简化了 HTTP 请求的发送和处理。支持HTTP工厂模式,支持单例模式,支持更多的简化API,支持链式调用等。

主要特性

  • 支持多种认证方式(API Key、Basic、Bearer Token、自定义)
  • 请求构建器模式
  • 支持重试、超时、熔断等高级功能
  • 支持同步和异步操作
  • 支持 JSON 序列化/反序列化
  • 完全兼容 AOT 编译

使用示例

基本使用
using Sage.Http.Core;
using Sage.Http.Authentication;
using Microsoft.Extensions.Logging;
using System.Net.Http;

// 创建 HttpRequestManager
var httpClient = new HttpClient();
var logger = LoggerFactory.Create(builder => builder.
AddConsole()).CreateLogger<HttpRequestManager>();
var requestManager = new HttpRequestManager
(httpClient, logger);

// 设置认证
requestManager.SetDefaultAuthProvider(new 
BearerTokenAuthProvider("your-token"));

// 发送 GET 请求
var response = await requestManager.GetAsync("https://
api.example.com/data");
if (response.IsSuccessStatusCode)
{
    var content = await response.Content.
    ReadAsStringAsync();
    Console.WriteLine(content);
}

// 发送 POST 请求并反序列化 JSON 响应
var data = new { Name = "Test", Value = 123 };
var result = await requestManager.
PostJsonAsync<ResponseType>("https://api.example.com/
data", data);
Console.WriteLine($"Result: {result.Status}");

重试和熔断配置的DI
// 读取HTTP客户端配置
var httpClientSettings = builder.Configuration.GetSection("HttpClients").Get<HttpClientSettings>()
      ?? throw new InvalidOperationException("未找到HTTP客户端配置,请检查appsettings.json文件");

// 1. 先注册HTTP客户端工厂配置(再http客户端功能)
  builder.Services.AddHttpRequestManagerFactory();

// 2. 再注册Http客户端及配置服务(包括基础配置,重试、熔断)
  builder.Services.AddHttpClientWithResilience(
      name: "ApiResourceServicesClient",
      configureClient: client =>
      {
          // 不使用BaseUrl
          //client.BaseAddress = new Uri(httpClientSettings.ApiResourceServicesClient.BaseUrl);
          client.Timeout = TimeSpan.FromSeconds(httpClientSettings.ApiResourceServicesClient.TimeoutSeconds);
          client.DefaultRequestHeaders.Add("Accept", "application/json");
          // 开启http3的支持
          client.DefaultRequestVersion = new Version(3, 0);
          // 如果不支持自动降级
          client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
      },
      retryOptions: httpClientSettings.ApiResourceServicesClient.Retry, // 重试配置
      circuitBreakerOptions: httpClientSettings.ApiResourceServicesClient.CircuitBreaker // 熔断配置
    );

许可证

版权所有 © 2025 甲壳虫科技 团队。

贡献

欢迎提交问题和功能请求。 QQ Group: 1054304346

作者

甲壳虫科技

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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Sage.Http:

Package Downloads
Sage.CloudStorage.Qiniu

Sage.CloudStorage.Qiniu 是一个基于 .NET 平台的现代化七牛云存储 SDK,采用完全异步设计,提供了对七牛云对象存储、CDN 等服务的简单易用的 API 封装。该库基于 Sage.Http 构建,具有高性能、可扩展的七牛云服务访问能力,特别适合企业级应用和大文件处理场景。 ## 核心优势 - **现代化API设计**:完全异步,符合.NET最佳实践 - **模块化架构**:各组件职责明确,易于扩展和维护 - **丰富的事件机制**:提供上传进度通知和完成事件 - **智能上传策略**:自动选择最佳上传方式和分片大小 - **完善的错误处理**:提供详细的错误信息和恢复机制 ## 功能特性 - **完整的对象存储支持**:上传、下载、管理、删除等操作 - **高级上传功能**: - 智能分片上传(自动优化分片大小) - 断点续传支持 - 并发控制 - 实时进度监控 - **CDN管理**:刷新、预取、带宽查询、日志下载 - **数据处理**:图片处理、音视频转码等 - **批量操作**:批量上传、删除等

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.5 22 9/23/2025
1.0.0.4 197 8/27/2025
1.0.0.3 250 8/25/2025
1.0.0.1 124 8/21/2025
1.0.0 130 7/16/2025