httpapihelper 1.0.1
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 httpapihelper --version 1.0.1
NuGet\Install-Package httpapihelper -Version 1.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="httpapihelper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add httpapihelper --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: httpapihelper, 1.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 httpapihelper as a Cake Addin #addin nuget:?package=httpapihelper&version=1.0.1 // Install httpapihelper as a Cake Tool #tool nuget:?package=httpapihelper&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
httpApiHelper
基于 System.Net.HttpWebRequest 封装,方便,易用;引用函数式编程思想,让代码更加的优雅,高可读性。
说明
- 只支持返回类型为 json 的请求
- .SetHeaders() 该方法不必须,为满足需要认证和请求头信息的请求而设
- .OnStart() 、.OnSuccess、.OnFailure()、.OnError() 这些方法不必须,与顺序无关。
- .OnSuccess、.OnFailure()、.OnError() 互斥,只会调用其中一个。
- 默认带Cookies 请求。
使用
Step 1:在nuget上添加对 httpapihelper 的引用或搜索 httpapihelper;;
Install-Package httpapihelper
Step 2:添加引用
using HttpApiHelper;
Step 3:使用 * GET 用法
//简单用法
public void TestGet()
{
string url = "http://127.0.0.1:8080/nbm/login/test";
HttpWebRequestHelper<List<User>>.Instance
.OnSuccess((result) =>
{
Console.WriteLine("Success ...");
List<User> Users = result.Data;
for (int i = 0; i < Users.Count; i++)
{
User m = Users[i];
Console.WriteLine("name:" + m.name + " age :" + m.age);
}
})
.Get(url);
}
//基本用法
public void TestGet()
{
string url = "http://127.0.0.1:8080/nbm/login/test";
HttpWebRequestHelper<List<User>>.Instance
.OnStart(() =>
{
Console.WriteLine("STart ...");
})
.OnSuccess((result) =>
{
Console.WriteLine("Success ...");
List<User> Users = result.Data;
for (int i = 0; i < Users.Count; i++)
{
User m = Users[i];
Console.WriteLine("name:" + m.name + " age :" + m.age);
}
})
.OnFailure((res) =>
{
Console.WriteLine("Failure ..code:+" + res.Code + "...msc:" + res.Message);
})
.OnError((res) =>
{
Console.WriteLine("Error ..code:+" + res.Code + "...msc:" + res.Message);
})
.Get(url); //不需要传参
//.Get(url, "name=code&age=56"); // 带参数
}
public void TestGet()
{
string url = "http://127.0.0.1:8080/nbm/login/test";
HttpWebRequestHelper<User>.Instance
.OnStart(() =>
{
Console.WriteLine("STart ...");
})
.OnSuccess((result) =>
{
Console.WriteLine("Success ...");
User m = result.Data;
Console.WriteLine("name:" + m.name + " age :" + m.age);
})
.OnFailure((res) =>
{
Console.WriteLine("Failure ..code:+" + res.Code + "...msc:" + res.Message);
})
.OnError((res) =>
{
Console.WriteLine("Error ..code:+" + res.Code + "...msc:" + res.Message);
})
//.Get(url); //不需要传参
.Get(url, "id=56"); // 带参数
}
- Post 用法
public void TestPost()
{
string url = "http://127.0.0.1:8080/nbm/login/test";
NameValueCollection collection = new NameValueCollection
{
{"name","code"},
{"age","80" },
{"salary","12.90" }
};
System.Net.WebHeaderCollection headerCollection = new System.Net.WebHeaderCollection
{
{"token","qmfamdfasdfm" }
};
User user = new User() { name = "code", age = 90, salary = 89.09 };
HttpWebRequestHelper<List<User>>.Instance
.OnStart(() =>
{
Console.WriteLine("-------------STart ...");
})
.OnSuccess((result) =>
{
Console.WriteLine("Success ...");
List<User> Users = result.Data;
for (int i = 0; i < Users.Count; i++)
{
User m = Users[i];
Console.WriteLine("name:" + m.name + " age :" + m.age + " salary:" + m.salary);
}
})
.OnFailure((res) =>
{
Console.WriteLine("Failure ..code:+" + res.Code + "...msc:" + res.Message);
})
.OnError((res) =>
{
Console.WriteLine("Error ..code:+" + res.Code + "...msc:" + res.Message);
})
.SetHeaders(headerCollection) // 不必须
// .Post(url, collection); //参数类型为 NameValueCollection
//.Post<User>(url, user); //参数为对像
//.Post(url, "name=code&age=56"); //参数为字符串
.Post(url); //不需要参数
}
string url = "http://127.0.0.1:8080/nbm/login/test";
HttpWebRequestHelper<User>.Instance
.OnSuccess((result) =>
{
Console.WriteLine("Success ...");
User Users = result.Data;
for (int i = 0; i < Users.Count; i++)
{
User m = Users[i];
Console.WriteLine("name:" + m.name + " age :" + m.age + " salary:" + m.salary);
}
})
.Post(url);
捐赠
如果您觉得httpHelper还不错,并且刚好有些闲钱,那么可以选择以下方式来捐赠:
- 支付宝
- 微信
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. net9.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- Newtonsoft.Json (>= 12.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.
optimize