异步HTTP请求,排队请求

发布于 2024-11-16 02:11:59 字数 457 浏览 1 评论 0原文

我之前为appstore开发过,并且使用过ASIHTTPRequest。 Android 有类似的东西吗?

我正在考虑发出一些 HTTP 请求,这些请求已排队且易于管理。这就是我需要做的:

  1. 设置一个包含 6 个 http 请求的队列。
  2. 设置队列后,对每个请求执行它,给出成功/失败结果。
  3. 如果一个请求失败,我可以选择取消/清除整个队列。
  4. 如果队列中的所有请求都成功,我可以对整个队列的成功事件进行另一个回调。
  5. 并且,每个请求可以有一个重试次数;意义;我可以说每个请求在返回失败之前可以重试 n 次。

IOS 的 ASIHTTPRequest 非常擅长处理这个问题。无论如何,我可以用 Android 来做到这一点吗?我返回的大部分内容都是 XML,没有二进制数据。

非常感谢任何反馈。

I have developed for appstore before and I used ASIHTTPRequest. Is there something similar for Android?

Am looking at making a few HTTP requests, which are queued and manageable. This is what I need to do:

  1. Set-up a queue of lets say 6 http requests.
  2. Once the queue is setup, execute it with each request giving me a success/failure result.
  3. If one request fails, I have the option to cancel/clear the whole queue.
  4. If all the requests in the queue are successful, I can have another callback for the whole queue's success event.
  5. And,each request can have a retry count; meaning; I can say each request can retry n number of time before they can return a failure.

ASIHTTPRequest for IOS was pretty good at handling this. Is there anyway I can do this with Android? Most of my content returned is XML and no binary data.

Any feedback is much appreciated.

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

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

发布评论

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

评论(1

听闻余生 2024-11-23 02:11:59

您所描述的构建起来并不太复杂。

  1. 扩展 java.util.Queue
  2. 创建自定义“侦听器”接口,用于处理您需要跟踪的所有事件。
  3. 允许设置“侦听器”的自定义请求对象。
  4. 您的自定义队列将有一个线程来处理其自己的队列中的项目。
  5. 根据您的具体要求,您可能还需要额外的接口/侦听器来将最终响应传回发出初始请求的对象。

将对象添加到队列时,您的队列会将自身设置为自定义请求对象的“侦听器”。

当事件在请求对象中发生时,将在侦听器对象上调用事件方法...在队列的情况下...可以做出适当的反应。

我怀疑像 ASIHTTPRequest 这样的东西在 Java/Android 中并不存在,因为它不像 iOS 上那样难以解决。我可以在 20 分钟或更短的时间内将上述对象实现为功能组件。当然,如果您以前没有做过类似的事情,那么可能会花费更长的时间。

What you describe is not overly complicated to build.

  1. Extend java.util.Queue
  2. Create custom "listener" interface which handles all the events you need to track.
  3. Custom request objects that allow a "listener" to be set.
  4. Your custom queue will have a thread to process items in it's own queue.
  5. Depending on your exact requirements, you may also need an additional interface/listener to pass back the final response to the object that made the initial request.

When adding an object to the queue, your queue would set itself as the "listener" on the custom request object.

When the events happen in the request object, the event methods will be called on the listener object...in the case the queue...which can react appropriately.

I suspect something like ASIHTTPRequest does not really exist in Java/Android, because it's not as difficult a problem to solve as on iOS. I could implement the above objects into a functional component in 20 minutes or less. Of course, if you've not done something like this before, it may take you much longer.

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