简体   繁体   English

Droid项目中引用的.NET Standard 2库中的HttpClient实现

[英]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?

Android选项

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.

相关问题 将 class 库项目升级到 .net 标准 2.1,其中 .net 框架 4.X 项目已引用该标准 - Upgrading class library project to .net standard 2.1 where this has been referenced by .net framework 4.X projects Xamarin-在.Net标准库中使用httpClient - Xamarin - Using httpClient in .Net Standard Library 设置解决方案中其他项目引用的dll类库的位置 - set location of dll class library which is referenced in other project in solution 从 .Net 标准类库引用 .Net Core 3.1 项目 - Referencing a .Net Core 3.1 project from a .Net Standard Class Library .NET Framework 4.7项目中的.NET标准类库 - .NET Standard Class Library in .NET Framework 4.7 project .NET 462 项目引用时,bin 中缺少 .NET Standard 2.0 dll 的瞬态依赖项 - Transient dependencies of .NET Standard 2.0 dll are missing in bin when referenced by .NET 462 project 我正在尝试通过 HttpClient 在 .net standard1.3 库中应用代理身份验证 - I am trying to apply a Proxy authentication through an HttpClient, in a .net standard1.3 library WPF中引用的.NET标准类库 - 在设计时在XAML中签名错误 - .NET Standard class library referenced in WPF - sign error in XAML at design time UWP中引用的.NET标准库中Process.Start的访问被拒绝错误 - Access denied error for Process.Start inside .NET Standard library referenced in UWP 哪个Twilio .Net帮助程序库适合新项目 - Which Twilio .Net helper library for new project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM