你好,我想问一些问题。我想制作一个应用程序,与我创建的Web服务连接。
我的应用程序有两个唯一标识符,称为app_id和token。app_id在应用程序第一次启动时仅生成一次,而token由Web服务生成。
每个请求,我必须检查token是否已过期,如果已过期,则调用单独的Web服务并生成新的token。
问题是应用程序必须访问2个不同的Web服务:请求新的token和获取其他所需数据。我使用asynctask,但是请求token的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;
}
}
谢谢您的信任!