多个HTTP POST按顺序进行 [英] Multiple HTTP POST in sequence
问题描述
我有一个应用程序欠发达,我需要按顺序执行3个HTTP POST。实现这个的最佳方法是什么?我应该
I have an app underdevelopment and I need to do 3 HTTP POSTs in sequence. What is the best way to implement this ? Should I
-
让每个HTTP Post都有自己的Async Class和菊花链Async类(即从中调用第二个异步)第一个异步的onPostExecute)
Make each HTTP Post in it own Async Class and daisy chain the Async classes(i.e. call the second async from the onPostExecute of the first Async)
将所有HTTP POST放在单个异步的doInBcakGround中。
Put all the HTTP POSTs in the doInBcakGround of a single Async.
我知道如何进行HTTP POST请求,而我正在使用OKHTTP lib。我只是想知道按顺序进行多个POST的最佳练习。
I know how to do a HTTP POST request and I am using the OKHTTP lib. I just would like to know that the best practice it for multiple POSTs in sequence.
干杯
推荐答案
您的第一种方法会更好和非常模块化,因为您可以跟踪应用程序中的任何内容。在三种不同的<$ c中$ c> AsyncTask 你可以检查 postExceute()
哪个 AsyncTask
是完成其工作(更容易和更精确)AND
Your first approach will be better and quite modular as you can keep the track of anything in your application.In the three different AsyncTask
you can have a check in postExceute()
that which AsyncTask
is done with its work (more easily and precisely) AND
>>>>>如果应用程序崩溃
然后 httpPost
中的哪一个失败。但是,第二个将使您的代码混乱,您将无法跟踪获取异常
哪个 httpPost
请求失败(尽管如此)。
then which of the httpPost
failed. However , the second one will make your code messy and you will be unable to track on getting Exception
that which httpPost
request failed(in a straight forward way though).
因此从第一个任务的onPostExecute启动第二个AsyncTask将是更好的方法。
这篇关于多个HTTP POST按顺序进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!