You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
978 B
C#

8 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace HttpClientStudy.UnitTest
{
public class DelegatingHandlerTest
{
private readonly ITestOutputHelper _logger;
public DelegatingHandlerTest(ITestOutputHelper outputHelper)
{
_logger = outputHelper;
}
[Fact]
public async Task Test()
{
//构建管道
var handler = new HandlerA()
{
//相当于下一个中间件(管道)
InnerHandler = new HandlerB()
};
HttpClient httpClient = new HttpClient(handler);
8 months ago
var sd = await httpClient.GetAsync(TestConfig.WebApiBaseUrl + "/api/");
8 months ago
var contentText = await sd.Content.ReadAsStringAsync();
_logger.WriteLine(contentText);
}
}
}