-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AndroidMessageHandler doesn't allow arbitrary HTTP methods #7291
Comments
@tipa Unfortunately, the answer hasn't changed since #3544 was closed - AndroidMessageHandler uses Java's HttpURLConnection (that was the whole point of creating the handler) which does NOT support any other methods than listed here.
@simonrozsival can you think of a way to to do it in a compatible way? |
@grendello Ok, that's what I expected :( And I assume something like this would be considered too hacky? It would be enough if I could subclass
|
@tipa I would suggest keeping Does this solve your problem?
AFAIK okhttp is used internally on Android, but it's not available in the standard APIs and to use it in an app directly, the app needs to add a dependency on the library and app size will increase. There is also the Cronet library that can be loaded from Google Play Services so it doesn't increase the app size, but it isn't available on all Android devices. I think that we are stuck with HttpURLConnection for the time being. |
I meant the version of
That would probably break at runtime, because the Java side would still compare the method against its list of accepted ones. It would be better if you were able to use one of the okhttp bindings from nuget.org, I suppose. |
The problem with this is that I cannot provide a Edit: I found I can use this on
I could test if that's actually the case. Would you consider implementing this hack in case it worked? |
I'm sorry but no. If setting the method this way worked, we could probably subclass |
@tipa the |
@simonrozsival Oh, thanks for that info. Are there plans to port the old functionality to .NET 6? Is there an open issue that I can subscribe to? |
@tipa I see. We have a tracking issue dotnet/runtime#45741 that is now assigned to the .NET 8 milestone, so we will likely improve the Android Crypto integration it in the next releases (.NET 8 should be released in November 2023), but there's no short-term solution for your app in .NET 6 itself I'm afraid. Maybe the OkHttp NuGet that @grendello suggested supports the combination of custom HTTP methods and ignoring invalid certificates? I'm not familiar with it so I can't promise it has the capabilities. @grendello although we didn't resolve @tipa's problem, I think we should close this issue now, because we won't be allowing arbitrary HTTP methods in AndroidMessageHandler due to HttpURLConnection limitations. |
Agreed. @tipa, we'll definitely think about some form of solution for your problem, but I can't promise any time frame since our options with Android are quite limited atm. |
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS 2022
Description
I am using HttpClient to send and receive data from servers via WebDAV.
To do so, Http methods like "PROPFIND" or "MKCOL" are required.
Using these http methods causes crashes in
HttpClient.SendAsync
:System.Net.WebException: 'Expected one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, PATCH] but was PROPFIND'
It crashes in AndroidMessageHandler here: https://github.com/xamarin/xamarin-android/blob/f348163bdca996645ffbc5d47dee3d908eff640c/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L979
There has been an issue filed previously: #3544
Unfortunately it was closed and no workaround was presented.
Steps to Reproduce
Did you find any workaround?
In legacy Xamarin Android I found a workaround by explicitly providing an instance of
HttpClientHandler
to the HttpClient constructor (instead of the default AndroidMessageHandler/AndroidClientHandler).However, this workaround stopped working with .NET6 Android as apparently, the
HttpClientHandler
internally uses aAndroidMessageHandler
, causing the problem to occur again.My current "workaround" is to set the
UseNativeHttpHandler
in my .csproj tofalse
. I can still manually createAndroidMessageHandler
and set use them to initializeHttpClients
, but when using a third-party library, that library might not offer a way to provide my own HttpClient, so it keeps usingHttpClientHandler
, even though it could useAndroidMessageHandler
So ideally, the
AndroidMessageHandler
could be changed so that it accepts arbitrary HTTP methods.Alternatively, it would be good if there was a way to force a
HttpClientHandler
to be used without having to set the project-wideUseNativeHttpHandler
property tofalse
.The text was updated successfully, but these errors were encountered: