0

我正在使用一个名为Refit的库来访问 RESTful 服务

public interface IApiClient
{
    [Get("/{Id}/shifttimes")]
    Task<ShiftTimesResponse> GetShiftTimes(int id);
}

我正在初始化 DI 中的接口:

builder.Register(ctx =>
        {
            var baseUri = new Uri(config.ApiUri);
            var client = RestService.For<IApiClient>(baseUri.OriginalString);
            return client;

        }).As<IApiClient>().InstancePerTenant();

然后在 myHandler 中使用:

public class ShiftTimesHandler
{
    private readonly IApiClient _apiClient;

    public ShiftTimesHandler(
            IApiClient apiClient)
    {
       _apiClient= apiClient;
    }

    public async Task Execute(Message message)
    {
       **Error on this line**
        var shiftTimesResponse = await _apiClient.GetShiftTimes(message.Id); 

        //Do something
    }
}

例外是:

无法建立 SSL 连接,请参阅内部异常。

内部异常是:

根据验证程序,远程证书无效。:AuthenticationException

4

1 回答 1

1

下面为我​​工作。但是,它不应该在生产环境中完成

            var httpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
            };

            var httpClient = new HttpClient(httpClientHandler)
            {
                BaseAddress = new Uri(config.ApiUri);
            };

            return RestService.For<IHoursApiClient>(httpClient);
于 2019-02-22T08:54:45.160 回答