![]() |
VOOZH | about |
dotnet add package Galosys.Foundation.HttpClient --version 26.5.20.1
NuGet\Install-Package Galosys.Foundation.HttpClient -Version 26.5.20.1
<PackageReference Include="Galosys.Foundation.HttpClient" Version="26.5.20.1" />
<PackageVersion Include="Galosys.Foundation.HttpClient" Version="26.5.20.1" />Directory.Packages.props
<PackageReference Include="Galosys.Foundation.HttpClient" />Project file
paket add Galosys.Foundation.HttpClient --version 26.5.20.1
#r "nuget: Galosys.Foundation.HttpClient, 26.5.20.1"
#:package Galosys.Foundation.HttpClient@26.5.20.1
#addin nuget:?package=Galosys.Foundation.HttpClient&version=26.5.20.1Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.HttpClient&version=26.5.20.1Install as a Cake Tool
成熟度: 🟢 稳定 — 生产可用,测试充分,活跃维护
Galosys.Foundation.HttpClient 是基于 Microsoft.Extensions.Http 和 Polly 的 HTTP 客户端模块,提供声明式 REST 客户端、请求头传播、服务发现集成、委托处理器等能力,简化微服务间的 HTTP 调用。
<PackageReference Include="Galosys.Foundation.HttpClient" Version="x.x.x" />
// Program.cs 或 Module 中
services.AddRestClient();
using System.Net.Http;
using System.Threading.Tasks;
[RestClient("https://api.example.com")]
public interface IUserService
{
[GetMapping("/api/users/{id}")]
Task<UserDto> GetUserAsync(int id);
[PostMapping("/api/users")]
Task CreateUserAsync(CreateUserRequest request);
[GetMapping("/api/users")]
Task<List<UserDto>> ListUsersAsync(int page = 1, int size = 10);
}
public class UserController : ControllerBase
{
private readonly IUserService _userService;
public UserController(IUserService userService)
{
_userService = userService;
}
[HttpGet("{id}")]
public async Task<UserDto> GetUser(int id)
{
return await _userService.GetUserAsync(id);
}
}
通过 AddHttpClient 注册自定义 DelegatingHandler:
services.AddHttpClient("MyClient")
.AddHttpMessageHandler<AuthTokenHandler>();
public class AuthTokenHandler : DelegatingHandler
{
private readonly ITokenProvider _tokenProvider;
public AuthTokenHandler(ITokenProvider tokenProvider)
{
_tokenProvider = tokenProvider;
}
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
var token = await _tokenProvider.GetTokenAsync();
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
return await base.SendAsync(request, cancellationToken);
}
}
services.AddHttpClient("MyClient")
.AddScopeAwareHttpHandler<ScopedDelegatingHandler>();
| 类 | 说明 |
|---|---|
RestClientAttribute |
标记接口为 REST 客户端,指定服务地址 |
GetMappingAttribute |
标记方法为 GET 请求,指定路径模板 |
PostMappingAttribute |
标记方法为 POST 请求,指定路径模板 |
RestClientDispatchProxy |
动态代理实现,处理接口方法调用 |
ScopeAwareHttpClientFactory |
支持 DI 作用域的 HttpClient 工厂 |
Web 应用自动启用请求头传播(通过 AddHeaderPropagation)。
通过 AddServiceDiscovery() 集成服务发现,支持:
Galosys.Foundation.HttpClient/
├── Galosys/Foundation/HttpClient/
│ └── RestClientDispatchProxy.cs # 动态代理实现
├── Microsoft/Extensions/DependencyInjection/
│ ├── HttpClientServiceCollectionExntensions.cs # 服务注册扩展
│ └── ScopeAwareHttpClientFactory.cs # 作用域感知工厂
├── RestClientModule.cs # 模块注册
└── README.md
[GetMapping]、[PostMapping] 特性标记(来自 System.Net.Http 命名空间)[GetMapping]/[PostMapping] 特性时会抛出 InvalidOperationException| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on Galosys.Foundation.HttpClient:
| Package | Downloads |
|---|---|
|
Galosys.Foundation.NacosNaming
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.Consul
Galosys.Foundation快速开发库 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.20.1 | 155 | 5/20/2026 |
| 26.5.19.1 | 144 | 5/19/2026 |
| 26.5.18.1 | 155 | 5/18/2026 |
| 26.5.15.1 | 159 | 5/15/2026 |
| 26.5.12.3 | 162 | 5/12/2026 |
| 26.5.12.2 | 134 | 5/12/2026 |
| 26.4.27.1-rc1 | 143 | 4/26/2026 |
| 26.4.25.1-rc1 | 141 | 4/25/2026 |
| 26.4.22.2-rc7 | 140 | 4/22/2026 |
| 26.4.22.2-rc6 | 136 | 4/22/2026 |
| 26.4.22.2-rc4 | 140 | 4/22/2026 |
| 26.4.22.2-rc3 | 123 | 4/22/2026 |
| 26.4.19.1-rc1 | 130 | 4/19/2026 |
| 26.4.12.8-rc1 | 129 | 4/12/2026 |
| 26.4.12.7-rc1 | 134 | 4/12/2026 |
| 26.4.12.5-rc1 | 110 | 4/12/2026 |
| 26.1.30.1-rc1 | 201 | 1/30/2026 |
| 26.1.29.1 | 202 | 1/29/2026 |
| 26.1.28.5 | 205 | 1/28/2026 |
| 26.1.28.4 | 210 | 1/28/2026 |