代码拉取完成,页面将自动刷新
using System.Net;
using System.Reflection;
using HttpAgent;
using HttpAgent.AspNetCore.Extensions;
using HttpAgent.Samples;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Shapeless.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpContextAccessor();
var cookieContainer = new CookieContainer();
cookieContainer.Add(new Uri("https://furion.net"), new Cookie("cookieName", "cookieValue"));
// 为默认客户端启用
builder.Services.AddHttpClient(string.Empty, client => { })
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
CookieContainer = cookieContainer,
UseCookies = false,
// 忽略 SSL 证书验证
ServerCertificateCustomValidationCallback = HttpRemoteUtility.IgnoreSslErrors,
SslProtocols = HttpRemoteUtility.AllSslProtocols,
AllowAutoRedirect = false
});
//.AddProfilerDelegatingHandler();
// 为特定客户端启用
builder.Services.AddHttpClient("furion", client => { client.BaseAddress = new Uri("https://furion"); });
//.AddProfilerDelegatingHandler();
builder.Services.TryAddTransient<AuthorizationDelegatingHandler>();
builder.Services.AddServiceDiscovery();
builder.Services.AddHttpRemote(options =>
{
// 注册单个 HTTP 声明式请求接口
// options.AddHttpDeclarative<ISampleService>();
// 扫描程序集批量注册 HTTP 声明式请求接口(推荐此方式注册)
options.AddHttpDeclarativeFromAssemblies(Assembly.GetEntryAssembly());
options.AddHttpDeclarativeExtractorFromAssemblies(Assembly.GetEntryAssembly());
options.AddHttpContentConverters(() => [new ClayContentConverter()]);
}).ConfigureOptions(options => options.JsonSerializerOptions.AddClayConverters())
.ConfigureHttpClientDefaults(clientBuilder =>
{
clientBuilder.AddServiceDiscovery();
clientBuilder.AddProfilerDelegatingHandler();
});
var app = builder.Build();
// 启用请求正文缓存(支持 Body 重复读)
app.UseEnableBuffering();
app.UseWebSockets();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。