Tom.HttpLib 1.0.1

Additional Details

Logo错了

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tom.HttpLib --version 1.0.1                
NuGet\Install-Package Tom.HttpLib -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="Tom.HttpLib" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tom.HttpLib --version 1.0.1                
#r "nuget: Tom.HttpLib, 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 Tom.HttpLib as a Cake Addin
#addin nuget:?package=Tom.HttpLib&version=1.0.1

// Install Tom.HttpLib as a Cake Tool
#tool nuget:?package=Tom.HttpLib&version=1.0.1                

HttpLib

便捷的Http库

如果你喜欢 HttpLib 项目,请为本项点亮一颗星 ⭐!


作者 Tom
QQ 17379620

目录

示例

创建请求

Http.Get("https://www.baidu.com")

添加参数

GET请求参数会自动注入到地址

data(new { test1 = "测试1", test2 = "测试2" })
data(new List<Val> {
	new Val("test1","测试1"),
	new Val("test2","测试2")
})
data(new Files("文件地址"))

添加请求头

header(new { accept = "*/*", userAgent = "Chrome" })
header(new List<Val> {
	new Val("accept","*/*"),
	new Val("user-agent","Chrome")
})

启用重定向

默认禁止

redirect(true)

设置超时时长

毫秒(默认不超时)

timeout(3000)

设置编码

默认utf-8

encoding('utf-8')

注入回调获取进度

字节大小

上传
requestProgress((bytesSent, totalBytes) => {
	double 进度 = (bytesSent * 1.0) / (totalBytes * 1.0);
	Console.Write("{0}% 上传", (Math.Round(进度, 2) * 100.0));
})
下载
responseProgress((bytesSent, totalBytes) => {
	if (totalBytes.HasValue)
	{
		double 进度 = (bytesSent * 1.0) / (totalBytes.Value * 1.0);
		Console.Write("{0}% 下载", (Math.Round(进度, 2) * 100.0));
	}
})

请求

异步错误

fail((Exception e) => {
})

异步请求

success((WebResult web,string result) => {
}).RequestAsync();

同步获取

RequestByString();

实例1

异步

Http.Get("https://www.baidu.com")
.redirect(true)
.requestProgress((bytesSent, totalBytes) => {
	double 进度 = (bytesSent * 1.0) / (totalBytes * 1.0);
	Console.Write("{0}% 上传", (Math.Round(进度, 2) * 100.0));
})
.requestProgress((bytesSent, totalBytes) => {
	double 进度 = (bytesSent * 1.0) / (totalBytes * 1.0);
	Console.Write("{0}% 上传", (Math.Round(进度, 2) * 100.0));
})
.fail((Exception e) => {
	Console.Write(e.GetType());
	Console.Write(e.Message);
})
.success((WebResult web,string result) => {
	Console.Write(result);
}).RequestAsync();

实例2

同步

string result = Http.Get("https://www.baidu.com")
.redirect(true)
.fail((Exception e) => {
	Console.Write(e.GetType());
	Console.Write(e.Message);
})
.RequestByString();
Console.Write(result);

WebResult介绍

代码 解释 说明
StatusCode 状态代码 200 为正常 常见的有404未找到、302重定向、502网址报错
ServerHeader 服务头 HTTP 200 OK BWS/1.1 Ver:1.1
IP 请求域的IP地址
AbsoluteUri 最终的地址
Type 服务指示类型 Content-Type
Header 响应头
Cookie Cookie
SetCookie Set-Cookie
OriginalSize 流原始大小 动态压缩
Size 流大小
FileName 文件名称 返回文件类型才有Content-Disposition
Location 重定向网址 302

版权和协议

HttpLib 项目基于 LGPL-3.0 开源协议开放项目源代码。本项目版权由项目发起人、开发者Tom所有。

依照 LGPL-3.0 协议规定:

您可以在任何商业软件中引用 HttpLib 的二进制库而无需支付任何与版权相关的费用; 如果您的项目使用并修改了 HttpLib 的源代码,那么您的项目也需要使用 LGPL 协议进行开源,并且在您的衍生项目中保留 HttpLib 的版权信息:Powered by HttpLib。 如果您需要在非开源的应用程序中使用 HttpLib 的源代码,为了保障您的合法权益,请考虑向项目作者购买商业授权。

Product 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  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.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.4 129 9/13/2024
3.0.3 116 7/1/2024
3.0.2 113 5/21/2024
3.0.0 113 4/24/2024
2.1.0 129 2/20/2024
2.0.9 118 2/20/2024
2.0.8 572 10/12/2022
2.0.7 474 8/10/2022
2.0.6 466 7/28/2022
2.0.5 507 7/16/2022 2.0.5 is deprecated because it has critical bugs.
2.0.4 460 7/14/2022
2.0.2 473 7/14/2022
1.0.6.2 566 4/10/2021
1.0.6.1 461 3/15/2021
1.0.5 436 2/27/2021
1.0.4 439 2/13/2021
1.0.3 434 2/3/2021
1.0.2 397 2/2/2021
1.0.1 427 2/2/2021 1.0.1 is deprecated.