我正在使用一个名为 Refit 的库访问 RESTful 服务
public interface IApiClient
{
[Get("/{Id}/shifttimes")]
Task<ShiftTimesResponse> GetShiftTimes(int id);
}
我正在 DI 中初始化接口(interface):
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
}
}
异常(exception)是:
The SSL connection could not be established, see inner exception.
内部异常是:
The remote certificate is invalid according to the validation procedure.: AuthenticationException
最佳答案
下面为我工作。但是,它不应该在生产环境中完成:
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);
关于c# - Webapi http 调用导致 SSL 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54803301/