[英]HttpClient implementation in .NET Standard 2 library which is referenced in Droid project
I have an instance of HttpClient in a .NET Standard 2 library and the Droid project references the library. 我在.NET Standard 2库中有一个HttpClient实例,Droid项目引用了该库。 In the Droid project HttpClient implementation is set to Android. 在Droid项目中,将HttpClient实现设置为Android。 Will the HttpClient implementation use java.net.URLConnection or the HttpClientHandler? HttpClient实现将使用java.net.URLConnection还是HttpClientHandler?
I want it to use the native HttpClient. 我希望它使用本机HttpClient。 In case it uses the managed HttpClientHandler, do I need to add a special case for Android in my shared code library like this: 如果它使用托管的HttpClientHandler,我是否需要在我的共享代码库中为Android添加一个特殊情况,如下所示:
// if we're on any other platform
HttpClient client = new HttpClient()
// if we're on Android
HttpClient client = new HttpClient(new Xamarin.Android.Net.AndroidClientHandler ())
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/http-stack?tabs=windows https://docs.microsoft.com/zh-cn/xamarin/android/app-fundamentals/http-stack?tabs=windows
If you specify in the project options the type of client, you just need to initialize the HttpClient(), without specifying it's type. 如果在项目选项中指定客户端的类型,则只需要初始化HttpClient(),而无需指定其类型。
From the docs: 从文档:
// This will use the default message handler for the application; as
// set in the Project Options for the project.
HttpClient client = new HttpClient();
// This will create an HttpClient that explicitly uses the CFNetworkHandler
HttpClient client = new HttpClient(new CFNetworkHandler());
// This will create an HttpClient that explicitly uses NSUrlSessionHandler
HttpClient client = new HttpClient(new NSUrlSessionHandler());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.