嵌入式项目的 C/C++ HTTP 客户端库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23842394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:33:47  来源:igfitidea点击:

C/C++ HTTP Client Library for Embedded Projects

c++chttpembeddedclient

提问by thegreendroid

So I have trawled through pages and pages of search results on StackOverflow and Google and I have come across very few C/C++ HTTP client libraries suitable for a resource-constrained, embedded environment (e.g. an ARM). I have however come across quite a few that are suitable for desktop-class applications.

因此,我在 StackOverflow 和 Google 上搜索了一页又一页的搜索结果,发现很少有适用于资源受限的嵌入式环境(例如 ARM)的 C/C++ HTTP 客户端库。然而,我遇到了很多适用于桌面级应用程序的应用程序。

Essentially, I am after a simple, easy-to-use and convenient API to make HTTP GET, POST and HEAD calls (with support for authentication, download resume and payload compression). It would be ideal if it had a small footprint (i.e. no or minimal external dependencies) and is open-source (with a permissive license).

本质上,我想要一个简单、易用且方便的 API 来进行 HTTP GET、POST 和 HEAD 调用(支持身份验证、下载恢复和有效负载压缩)。如果它占用空间小(即没有或最小的外部依赖项)并且是开源的(具有宽松的许可证),那将是理想的。

Here's a list of what I've come across so far and why they are not suitable -

这是我迄今为止遇到的列表以及为什么它们不合适-

Are there any libraries out there that I am unaware of or am I better off rolling my own?

有没有我不知道的图书馆,还是我最好自己动手?

采纳答案by escrafford

Have you taken a look at the HTTPClient on mbed? Looks like there are lots of forks of an original from a few years ago that wasn't maintained. I haven't used this...

你看过 mbed 上的 HTTPClient 了吗?看起来几年前有很多没有维护的原版叉子。我没用过这个...

http://mbed.org/users/WiredHome/code/HTTPClient/

http://mbed.org/users/WiredHome/code/HTTPClient/

回答by Andik

I found another one, which just needs to be packed into a lib. didn't test it, but may be worth a look:

我找到了另一个,它只需要打包到一个库中。没有测试它,但可能值得一看:

https://github.com/reagent/http.git

https://github.com/reagent/http.git

回答by Arkady

I can just describe what I used for those tasks.

我只能描述我用于这些任务的内容。

curl- if you are lazy, you can just download in built binary and have nothing to do more, it has very simple headers and a lot of examples. You will need 3-4 already built libraries and header. With no external dependencies. So, I would count it as too low-level, but not heavyweight at all.

curl- 如果你很懒惰,你可以只下载内置的二进制文件而无需做更多的事情,它有非常简单的标题和很多例子。您将需要 3-4 个已经构建的库和头文件。没有外部依赖。所以,我认为它太低级了,但根本不是重量级。

boost.asio- very interesting paradigm of realization, quite easy and clean. But I would say it is low-level too. Harder then curl. And needs to use boost, that is external dependency you want to avoid, I guess.

boost.asio- 非常有趣的实现范例,非常简单和干净。但我会说它也是低级的。更难然后卷曲。并且需要使用boost,这是您想要避免的外部依赖,我猜。

poco- best solution for http server. It's high level, after you joined it to your application, you just need to implement few virtual functions, having all other work (and thread management) done. Poco gives a lot of stuff for application management, thread/process management and it is very simple and easy, I would even say it has java-like interface. Yes, there is external dependency to poco, but I would look at this as a chance to learn perfect library. Still, for http clients it is really heavy.

poco- http 服务器的最佳解决方案。这是高级别的,在您将其加入应用程序后,您只需要实现几个虚拟函数,完成所有其他工作(和线程管理)。Poco 为应用程序管理、线程/进程管理提供了很多东西,它非常简单易用,我什至会说它有类似 java 的界面。是的,对poco有外部依赖性,但我认为这是学习完美库的机会。尽管如此,对于 http 客户端来说,它真的很重。

That is all my C++ experience with HTTP. Counting you need just client and don't need dependencies, I would offer you to look at libcurllibrary. It's cross-platform, easy, no dependencies and low-level enough to get all you need with network. And if you will have time - look at Poco, really, I believe you will fell in love with this library as I did. Hope that will be helpful.

这就是我使用 HTTP 的所有 C++ 经验。计算您只需要客户端而不需要依赖项,我会建议您查看libcurl库。它是跨平台的、简单的、没有依赖关系并且足够低级,可以通过网络获得您所需要的一切。如果你有时间 - 看看 Poco,真的,我相信你会和我一样爱上这个库。希望这会有所帮助。