HJMinimally.EasyHttp
1.0.6
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package HJMinimally.EasyHttp --version 1.0.6
NuGet\Install-Package HJMinimally.EasyHttp -Version 1.0.6
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="HJMinimally.EasyHttp" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HJMinimally.EasyHttp --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HJMinimally.EasyHttp, 1.0.6"
#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 HJMinimally.EasyHttp as a Cake Addin #addin nuget:?package=HJMinimally.EasyHttp&version=1.0.6 // Install HJMinimally.EasyHttp as a Cake Tool #tool nuget:?package=HJMinimally.EasyHttp&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HJMinimally.EasyHttp
基于HttpClient
封装的 Http 请求库。
用法
1 预载
预载配置并不是必须的,但是有助于我们进行一些通用基础设置,例如Headers、Accept、BaseUrl等等。
配置BaseUrl
之后,可以直接使用QEasyHttp.Uri()
代替QEasyHttp.Url()
,直接填写接口即可。
在AspNetCore
中:
services.AddEasyHttp(opts =>
{
opts.BaseUrl = "http://localhost:8080/";
opts.Accept = new[]
{
"application/json",
"text/plain",
"*/*"
};
opts.EnableCompress = false;
opts.Headers = new[]{
("X-Ca-Test", "key")
};
});
较为通用的写法,程序构建时:
QEasyHttp.AddEasyHttp(opts =>
{
opts.BaseUrl = "http://localhost:8080/";
opts.Accept = new[]
{
"application/json",
"text/plain",
"*/*"
};
opts.EnableCompress = false;
opts.Headers = new[]{
("X-Ca-Test", "key")
};
})
2 全局配置 Authentication
有时需要全局配置 Authentication,如果在代码中请求中独立配置了 Authentication 则会覆盖全局 Authentication
QEasyHttp.InitAuthentication("Bearer", "Values");
如果你是塞到 Header 里的这种做法
QEasyHttp.AddHeader("X-Ca-Key", "Values");
3 Http 请求
3.1 QEasyHttp
API 示例:
var result = await QEasyHttp.Url("https://www.baidu.com/")
.Header("X-Ca-Key", "XXX")
.Authentication("Bearer", "XXX")
.Params(new { Id = "123456" })
.Body(new { })
// .Form(...)
// .File(...)
.PostAsync<string>();
简单示例:
// 配置BaseUrl
var services = new ServiceCollection();
services.AddEasyHttp(opts =>
{
opts.EnableCompress = false;
opts.BaseUrl = "http://localhost:5050/";
});
var res = await QEasyHttp.Uri("/Test/Get").Params(new { Id = "123456" }).GetAsync<object>();
var res = await QEasyHttp.Uri("/Test/TestGetResult").Params(new { Id = "123456", Ids = new[] { "123", "456" } }).GetAsync<object>();
var res = await QEasyHttp.Uri("/Test/Post").Body(new { Id = "123456", Ids = new[] { "123", "456" } }).PostAsync<object>();
var res = await QEasyHttp.Uri("/Test/PostResult")
.Params(new { Id = "123456", Ids = new[] { "123", "456" } })
.Body(new { Id = "123456", Ids = new[] { "123", "456" } })
.PostAsync<object>();
var res = await QEasyHttp.Uri("/Test/Delete").Params(new { Id = "123456" }).DeleteAsync<object>();
var res = await QEasyHttp.Uri("/Test/DeleteResult").Params(new { Id = "123456", Ids = new[] { "123", "456" } }).DeleteAsync<object>();
var res = await QEasyHttp.Uri("/Test/Put").Params(new { Id = "123456" }).PutAsync<object>();
var res = await QEasyHttp.Uri("/Test/PutResult")
.Body(new { Id = "123456", Ids = new[] { "123", "456" } })
.PutAsync<object>();
var res = await QEasyHttp.Uri("Patch").Params(new { Id = "123456" }).PatchAsync<object>();
var res = await QEasyHttp.Uri("PatchResult")
.Body(new { Id = "123456", Ids = new[] { "123", "456" } })
.PatchAsync<object>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- HJMinimally.Core (>= 1.0.1)
- HJMinimally.Utility (>= 2.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.