src/YL.Utils/Http/HttpClientUtil.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using YL.Utils.Check;
using YL.Utils.Extensions;
using YL.Utils.Security;
using YL.Utils.Json;
namespace YL.Utils.Http
{
public class HttpClientUtil
{
public static string HttpPost(string url, Dictionary<string, string> postData = null, Dictionary<string, string> headers = null)
{
CheckNull.ArgumentIsNullException(url, nameof(url));
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None };
using (var http = new HttpClient(handler))
{
if (headers != null)
{
foreach (var header in headers)
{
http.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
using (HttpContent httpContent = new StringContent(BuildParam(postData), Encoding.UTF8))
{
HttpResponseMessage response = http.PostAsync(url, httpContent).Result;
return response.Content.ReadAsStringAsync().Result;
}
}
}
public static T HttpPost<T>(string url, Dictionary<string, string> postData = null, Dictionary<string, string> headers = null)
{
CheckNull.ArgumentIsNullException(url, nameof(url));
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None };
using (var http = new HttpClient(handler))
{
if (headers != null)
{
foreach (var header in headers)
{
http.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
using (HttpContent httpContent = new StringContent(BuildParam(postData), Encoding.UTF8))
{
HttpResponseMessage response = http.PostAsync(url, httpContent).Result;
return response.Content.ReadAsStringAsync().Result.ToObjL<T>();
}
}
}
public static string HttpGet(string url, Dictionary<string, string> postData = null, Dictionary<string, string> headers = null)
{
CheckNull.ArgumentIsNullException(url, nameof(url));
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None };
using (var http = new HttpClient(handler))
后面还有 84 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。