I have a custom HttpClientHandler class which inherits from HttpClientHandler and for most scenarios it is used with the HttpClient as var client = new HttpClient(new CustomHttpClientHandler())
and it is working fine but I have a case where instead of HttpClient I have ODataClient, so is there anyway I can use my httpclient handler with the ODataClient?
Asked
Active
Viewed 219 times
0

Mohaned Mohamed
- 1
- 1
1 Answers
0
Add OnApplyClientHandler
to the ODataClientSettings
:
public static ODataClient Client(Uri uri)
{
var credentials = CredentialCache.DefaultCredentials;
var settings = new ODataClientSettings(uri, credentials)
{
OnTrace = (x, y) => Logger.Info(x, y),
OnApplyClientHandler = ClientHandler
};
return new ODataClient(settings);
}
private static void ClientHandler(HttpClientHandler obj)
{
obj.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
}