You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When doing a HTTP request with expired certificate, using HttpClient in .NET 7 Android app, the wrong exception type returned.
Expected: HttpRequestException. Returned: WebException.
Documentation of HttpClient.SendAsync indicates HttpRequestException or TaskCanceledException should be thrown.
Steps to Reproduce
var httpClient = new HttpClient();
try
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://expired.badssl.com/");
var response = await httpClient.SendAsync(request);
}
catch(HttpRequestException ex)
{
Console.WriteLine("SUCCESS HttpRequestMessage: " + ex);
}
catch(Exception ex)
{
Console.WriteLine("FAIL " + ex);
}
in .NET 7 Android app using native HTTP handler.
No issues when using SocketsHttpHandler.
Expected behavior
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
It would be nice if the returned exception matches SocketHttpHandler by returning HttpRequestException with inner AuthenticationException and then Javax.Net.Ssl.SSLHandshakeException as inner.
Note that WebClient returns the same exception and that should keep working.
Did you find any workaround?
Simply use broader catch.
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
Fixes: dotnet#7629
Whenever a Java backend connection fails for any reason, we wrap the
thrown exception in `HttpRequestException` as described in the
`HttpClient.SendAsync` documentation.
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS2022 17.4.2
Description
When doing a HTTP request with expired certificate, using HttpClient in .NET 7 Android app, the wrong exception type returned.
Expected: HttpRequestException. Returned: WebException.
Documentation of HttpClient.SendAsync indicates HttpRequestException or TaskCanceledException should be thrown.
Steps to Reproduce
in .NET 7 Android app using native HTTP handler.
No issues when using SocketsHttpHandler.
Expected behavior
Actual behavior
AndroidApp7.zip
It would be nice if the returned exception matches SocketHttpHandler by returning HttpRequestException with inner AuthenticationException and then Javax.Net.Ssl.SSLHandshakeException as inner.
Note that WebClient returns the same exception and that should keep working.
Did you find any workaround?
Simply use broader catch.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: