0

HttpServerインスタンスを に直接渡すことで、いくつかのメモリ内統合テストを作成していますHttpClient。また、どのように配線できHttpClientHandlerますか?

Establish ctx = () =>
{
    var config = new HttpConfiguration();
    config.Routes.MapHttpRoute(name: "Default", routeTemplate: "api/{controller}/{id}", defaults: new { controller = "values", id = RouteParameter.Optional });
    config.MessageHandlers.Add(new CompressionHandler());

    var server = new HttpServer(config)
    {
        InnerHandler = new DecompressionHandler()
    };
    client = new HttpClient(server);
};
4

2 に答える 2

2

ハンドラをチェーンできます:

var handler = new HttpServer(config)
{
    InnerHandler = new HttpClientHandler()
};

HttpClient client = new HttpClient(handler);

詳細 (驚き! :-) asp.net - http://www.asp.net/web-api/overview/working-with-http/http-message-handlers

于 2012-09-24T12:09:03.377 に答える
1

For testing a client handler I had to actually set the HttpServer as the inner handler:

var server = new HttpServer(config);

var handler = new DecompressionHandler
{
    InnerHandler = server
};

client = new HttpClient(handler);  
于 2012-09-24T17:32:54.823 に答える