I'm using the OWIN TestServer which provides me an HttpClient to do my in memory calls to the test server. I'm wondering if there's a way of passing in the existing HttpClient for Flurl to use.
相关问题
- Register MicroServices in Azure Active Directory (
- C# httpClient (block for async call) deadlock
- InvalidOperationException on a PostAsXmlAsync call
- HttpClient PCL Cookies Not Being Applied to Reques
- What is the new Startup.cs file for in Visual Stud
相关文章
- 在DotNetFx Owin 环境下调用 opencc.dll 报错
- C# HttpClient.SendAsync always returns 404 but URL
- Add claims with Owin Middleware
- Should I cache and reuse HttpClient created from H
- Get expire time of OAuth session
- Read headers from HttpResponseMessage before Conte
- How to set Claims from ASP.Net OpenID Connect OWIN
- Authenticating requests to Microsoft.Owin.Testing.
UPDATE: Much of the information below is no longer relevant in Flurl.Http 2.x. Specifically, most of Flurl's functionality is contained in the new
FlurlClient
object (which wrapsHttpClient
) and not in a custom message handler, so you're not losing functionality if you provide a differentHttpClient
. Further, as of Flurl.Http 2.3.1, you no longer need a custom factory to do this. It's as easy as:Flurl provides an
IHttpClientFactory
interface that allows you to customizeHttpClient
construction. However, much of Flurl's functionality is provided by a customHttpMessageHandler
, which is added toHttpClient
on construction. You wouldn't want to hot-swap it out for an already instantiatedHttpClient
or you'll risk breaking Flurl.Fortunately, OWIN TestServer is also driven by an
HttpMessageHandler
, and you can pipeline multiple when you create anHttpClient
.Start with a custom factory that allows you to pass in the
TestServer
instance:Factories can be registered globally, but since you need a different
TestServer
instance for each test, I'd recommend setting it on theFlurlClient
instance, which is a new capability as of Flurl.Http 0.7. So your tests would look something like this: