在Xamarin核心项目中使用HttpClient [英] Using HttpClient in a Xamarin core project

查看:320
本文介绍了在Xamarin核心项目中使用HttpClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个针对多个平台的项目,在这些平台上,我遵循了最佳实践,并创建了一个核心项目来包含所有平台上相同的所有代码。
要进行网络通信,我想使用HttpClient,这似乎是与以后进行Web服务通信的推荐方法。

I am doing a project for multiple platforms where I have followed best practices and created a core project to contain all the code that is the same on all platforms. To do the network communication I would like to use HttpClient which seems to be the recommended approach for communicating with web services going forward.

我不是在做PCL只是一个标准C#库,用于包含核心项目。但是,似乎没有通用的HttpClient实现,只有平台特定的实现。我不能在我的核心中引用和使用它,而只能在我的Android和iOS项目中使用。

I am NOT doing a PCL but just a standard C# library to contain the core project. However it seems that there is no common implementation of HttpClient but only platform specific ones. I cannot reference and use it in my core but only in my Android and iOS projects.

我非常希望在我的核心项目中有所有的网络代码看到它有两个选择-我都不喜欢。

I would very much prefer to have all networking code in my core project and as I see it there are two options - neither of which I like.


  1. 为实现的核心项目使用一个通用接口作为Android和iOS上的包装器。

  2. 使用核心项目中支持的另一种技术-我正在考虑使用webclient等。

推荐的方法是什么?为什么Xamarin没有将HttpClient用作公共库?

What is the recommended approach and why hasn't Xamarin made HttpClient available as a common library?

希望有人可以提供帮助,
谢谢

Hope someone can help, Thanks

推荐答案

我建议您查看ModernHttpClient https://github.com/paulcbetts/modernhttpclient

I recommend checking out ModernHttpClient https://github.com/paulcbetts/modernhttpclient

这是一个适用于iOS和Android的跨平台网络库。来自项目:

It is a cross-platform networking library for iOS and Android. From the project:


该库通过自定义HttpClient处理程序将最新的特定于平台的网络库
带到Xamarin应用程序。使用System.Net.Http编写
应用程序,但是将其放入该库中,它将大大加快
的运行速度。

This library brings the latest platform-specific networking libraries to Xamarin applications via a custom HttpClient handler. Write your app using System.Net.Http, but drop this library in and it will go drastically faster.

这篇关于在Xamarin核心项目中使用HttpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆