How to add client certificate in ASP.NET Web API in-memory testing?

前端 未结 1 519
梦谈多话
梦谈多话 2021-01-23 06:26

I want to test my Web API service using in-memory HttpServer.

The current setup looks the following:

 var httpConfig = CreateTestHttpConfigu         


        
相关标签:
1条回答
  • 2021-01-23 07:03

    This approach will do it:

            var server = new HttpServer(configuration);
            var invoker = new HttpMessageInvoker(server);
            var certificate = GetCertificate();
    
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/YourPath");
            request.Properties[HttpPropertyKeys.ClientCertificateKey] = certificate;
            var result = await invoker.SendAsync(request, CancellationToken.None);
    
    0 讨论(0)
提交回复
热议问题