Java简单异步HTTPS客户端

发布于 2024-12-06 04:47:41 字数 716 浏览 1 评论 0原文

我需要开发一个与 https 服务器通信的应用程序。 该应用程序需要执行一些异步数据传输。

我首先尝试使用 HttpsURLConnection 并使用带有可观察对象的单独线程来管理返回的 inputStream。观察者类将调用更新方法来执行一些操作。 这种方法的问题是我在这里读到: HTTPUrlConnection错误(从 inputStream 读取后无法打开 OutputStream) HttpUrlConnection 无法处理多个写入/读取。无论如何,那个帖子对我没有帮助。

我读到了 Jetty 和 Apache HttpClient,但这些库分别为 2.8 和 4 兆字节,比我必须编写的应用程序大 10 倍以上。

所以:我正在寻找一个非常简单且可能是轻量级的java库来处理异步https连接,或者一种多次使用像HttpURLConnection这样的连接的方法(第二种解决方案将更受赞赏,因为我的程序不需要做任何更复杂的事情,我不必导入任何其他库)。

顺便说一句:我正在使用 sun httpServer 来制作 https 服务器,如果知道的话很有用。 如果您需要我发布我的代码的某些部分,以便您更好地理解我正在做的事情,请询问。

谢谢

I need to develop an application that comunicates with an https server.
This application needs to do some asynchronous data transfert.

I first tried to use an HttpsURLConnection and manage the returned inputStream using a separate thread with an observable object. The observer class than would call the update method that would do some stuff.
The problem with this approach is that i read here: HTTPUrlConnection error (Can't open OutputStream after reading from an inputStream) that HttpUrlConnection can't handle more than a single write/read. That post didn't help me anyway.

I read about Jetty and the Apache HttpClient, but those libraries are 2.8 and 4 megabytes, that is more than 10 times bigger than the application i have to write.

So: I'm looking for a really simple and possibly lightweight java libraries to handle an asynchronous https connection, or a way to use multiple times a connection like the HttpURLConnection (the second solution would be more appreciated as my program doesn't need to do anything more complex and i don't have to import any other libraries).

btw: i'm using the sun httpServer to make the https server if it is useful to know.
If you need me to post some parts of my code to make you better understand what i'm making just ask.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命比纸薄 2024-12-13 04:47:41

如果库大小确实很重要,您可以考虑使用HttpCoreHttpCore 是 Apache HttpClient 所基于的一组低级 HTTP 传输组件。它的占用空间约为 200-250 KB。

If the library size truly matters, you could consider using HttpCore. HttpCore is a set of low level HTTP transport components Apache HttpClient is based on. It's footprint is approximately 200-250 KB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文