У меня есть этот код в моем проекте. < /p>
var webRequest = (HttpWebRequest)WebRequest.Create(new Uri(requestAddress));
webRequest.ClientCertificates.Add(certificate);
webRequest.Method = WebRequestMethods.Http.Post;
Теперь я хочу перенести его в httpclient . Перед переключением я хочу написать хороший тест и увидеть, что он успешен для обоих. Как я могу написать такой сервер?var builder = WebApplication.CreateBuilder();
builder.Logging.ClearProviders();
builder.Logging.AddDebug();
builder.WebHost.UseHttpSys(options =>
{
options.ClientCertificateMethod = ClientCertificateMethod.AllowCertificate;
options.UrlPrefixes.Add($"http://localhost:5001/TestHost");
});
builder.Services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme).AddCertificate(options =>
{
options.Events = new CertificateAuthenticationEvents
{
OnCertificateValidated = context =>
{
// Never gets here
var certificate = context.ClientCertificate;
return Task.CompletedTask;
}
};
});
builder.Services.AddSingleton(new StartupFilter());
_app = builder.Build();
_app.Use(async (context, next) =>
{
var certificate = context.Connection.GetClientCertificateAsync().Result;
// certificate is null here
};
_app.UseAuthentication();
_app.MapPost("/tests/endpoint1", (object requestData) => { return "any"; });
_app.Run();
Подробнее здесь: https://stackoverflow.com/questions/797 ... rtificates