你好我想问一些问题我想制作与我制作的网络服务连接的应用程序
我的应用程序有 2 个名为 app_id 和令牌的唯一 ID,app_id 仅在应用程序首次启动时生成一次,令牌由 Web 服务生成
每个请求,我必须检查令牌是否已过期,如果令牌已过期,它将调用单独的 Web 服务并生成新令牌
问题是应用程序必须访问 2 个不同的 Web 服务:请求新令牌并获取另一个所需数据
我使用 asynctask,但是 Web 服务对请求令牌的响应总是相同的每个请求,我不知道为什么
protected Boolean doInBackground(Void... params) {
int status = 0;
int token_expired=0;
String token_val = token.getToken(getBaseContext());
for(int i=0;i<5 && status==0;i++) {
try {
Thread.sleep(1000);
//function to check if token already expired or not and request new token using http post
token_expired = token.checkToken(getBaseContext());
System.out.println("token expired: " +token_expired);
if (token_expired==1 || token_expired==2) {
//function to call another web service and get a data from it
status = rclient.Execute("POST");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (status==0) {
return false;
}else{
return true;
}
}
之前谢谢!