异步HTTP请求,排队的请求 [英] Asynchronous HTTP Request, queuing requests

查看:1367
本文介绍了异步HTTP请求,排队的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前开发的AppStore和我用 ASIHTT prequest 。是否有类似的东西为Android?

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

期待在做一些HTTP请求,这是排队和管理。这是我需要做的:

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

  1. 中建立一个队列可以说6 HTTP请求。​​
  2. 当队列设置,与每个请求给我一个成功/失败的结果执行。
  3. 如果一个请求失败,我不得不取消/清除整个队列的选项。
  4. 如果在队列中的所有请求都成功,我能有另一个回调对整个队列的成功事件。
  5. 另外,每个请求可以有一个重试次数;含义;我可以说每个请求可以重试时间N多,才可以返回一个失败。

ASIHTT prequest 的IOS是pretty的善于处理这一点。反正我有可以与Android做到这一点?我的大部分内容返回的XML和没有二进制数据。

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.

任何反馈是非常AP preciated。

Any feedback is much appreciated.

推荐答案

你描述的不是太复杂打造。

What you describe is not overly complicated to build.

  1. 扩展java.util.Queue中
  2. 创建负责处理所有需要跟踪的事件自定义监听器​​界面。
  3. 允许一个监听器​​
  4. 在自定义请求对象进行设置。
  5. 您的自定义的队列将有一个线程来处理它自己的队列中的项目。
  6. 根据您的具体要求,可能还需要额外的接口/监听器来传递回,使得初始请求对象的最终响应。
  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.

我怀疑是这样ASIHTT prequest并没有真正的Java / Android的存在,因为它不是一个很难解决的问题是在iOS。我可以在20分钟以下实施上述目的成一个功能组件。当然,如果你没有做过这样的事情之前,它可能需要更长的时间。

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.

这篇关于异步HTTP请求,排队的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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