newdcm.Net
1.0.1
dotnet add package newdcm.Net --version 1.0.1
NuGet\Install-Package newdcm.Net -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="newdcm.Net" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="newdcm.Net" Version="1.0.1" />
<PackageReference Include="newdcm.Net" />
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 newdcm.Net --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: newdcm.Net, 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.
#:package newdcm.Net@1.0.1
#: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=newdcm.Net&version=1.0.1
#tool nuget:?package=newdcm.Net&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
1. HTTP请求或FormData读取、Json转换等常用工具
1.1 DataTableToJsonConverter类
DataTable对象序列化与反序列化(一般情况下只用到WriteJson来将DataTable转换为Json)
//将一个DataTable序列化为json串
string json = JsonConvert.SerializeObject(table, new Serialization.DataTableConverter());
//将json反序列化为DataTable对象
DataTable table = JsonConvert.DeserializeObject<DataTable>(json, new Serialization.DataTableConverter());
//在webapi中,可以将此加到Converters中去
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new Serialization.DataTableConverter());
转换后的json如下:
{
columns:["col1","col2"],
rows:[
["val11","val12"],
["val21","val22"]
]
}
1.2 FormDataReader类: 用于multipart/form-data与application/x-www-form-urlencoded类型的请求读取为一个对象
//先定义一个与FormData表单中键值对应的对象
// 注:存在JsonPropertyName的优先以JsonPropertyName去找formdata中的键,不存在则直接用列名
public class MyObject
{
[JsonPropertyName("message")]
public string Message { get; set; }
[JsonPropertyName("url")]
public string Url { get; set; }
[Newtonsoft.Json.JsonProperty("pdfFile")]
public IFormFile PdfFile { get; set; }
}
// 从form-data请求上接收请求,转换为对象
var myobj = await _formReader.BindAsync<MyObject>(httpRequest);
1.3 HttpHelper类:用于处理Http请求的类
支持Get,Post,Put,Delete请求,以及通过FormData方式上传文件的请求
//各种Get请求
HttpResponseMessage rsps = _httpHelper.Get(url);
HttpResponseMessage rsps = _httpHelper.Get(url,args);
string strRsps = _httpHelper.GetStringResult(url,args);
MyClass objRsps = _httpHelper.GetObject<MyClass>(url,args);
// 文件下载
var memroyStream = await _httpHelper.GetFileStream(fileUrl);
//各种Post请求
HttpResponseMessage rsps = _httpHelper.Post(url,jsonStr);
HttpResponseMessage rsps = _httpHelper.PostObject<MyClass>(url,myClassObj);
string strRsps = _httpHelper.PostJsonString(url,jsonStr);
string strRsps = _httpHelper.PostObjectReturnString<MyClass>(url,myClassObj);
MyResult result = _httpHelper.PostObjectReturnObject<MyResult,MyClass>(url,myClassObj);
//使用Post的MultipartFormData方式上传文件
Dictionary<string,string> formStringKeyValues = new Dictionary<string,string>();
formStringKeyValues.add("id","1");
formStringKeyValues.add("name","yass");
string fileKey = "photo";
string fileLocal1 = "d:\\photo1.jpg";
string fileLocal2 = "d:\\photo2.jpg";
HttpResponseMessage rsps = _httpHelper.PostFiles(url,formStringKeyValues,fileKey,new List<string>(){fileLocal1,fileLocal2});
string strResult = _httpHelper.PostFilesReturnString(url,formStringKeyValues,fileKey,new List<string>(){fileLocal1,fileLocal2});
MyClass myObj = _httpHelper.PostFilesReturnObject<MyClass>(url,formStringKeyValues,fileKey,new List<string>(){fileLocal1,fileLocal2});
//PUT请求与Post差不多,除了HttpMethod不一样,此处省略示例
//Delete请求
HttpResponseMessage delRsps = _httpHelper.Delete(url);
MyClass myObj = _httpHelper.DeleteReturnObject<MyClass>(url);
1.4 UserAgentHelper类:从HttpRequest请求的UserAgent串中分析客户端信息,返回HttpClientInfo对象
获取的信息包括:是否为浏览器、是否为机器人程序、是否为移动端、操作系统版本、浏览器类型与版本等
HttpClientInfo? clientInfo = UserAgentHelper.Instance().GetClientInfo(string userAgentStr);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. 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.
-
net8.0
- Microsoft.AspNetCore.Hosting (>= 2.3.9)
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.3.9)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- Newtonsoft.Json (>= 13.0.4)
- Ng.UserAgentService (>= 3.0.0)
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 |
|---|---|---|
| 1.0.1 | 98 | 4/11/2026 |