我正在通过将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);
};
答案 0 :(得分:2)
您可以链接处理程序:
var handler = new HttpServer(config)
{
InnerHandler = new HttpClientHandler()
};
HttpClient client = new HttpClient(handler);
更多信息(惊喜!:-) at asp.net - http://www.asp.net/web-api/overview/working-with-http/http-message-handlers
答案 1 :(得分:1)
为了测试客户端处理程序,我必须将HttpServer
实际设置为内部处理程序:
var server = new HttpServer(config);
var handler = new DecompressionHandler
{
InnerHandler = server
};
client = new HttpClient(handler);