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

为了测试客户端处理程序,我必须将其实际设置HttpServer内部处理程序:

var server = new HttpServer(config);

var handler = new DecompressionHandler
{
    InnerHandler = server
};

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