连接的第一次是正常返回,然后剩下的每次都报这样的错:
12-03 18:07:09.470: W/(5047):
12-03 18:07:09.470: W/(5047): at (:557)
12-03 18:07:09.470: W/(5047): at (:487)
12-03 18:07:09.470: W/(5047): at (:74)
12-03 18:07:09.470: W/(5047): at (:91)
12-03 18:07:09.470: W/(5047): at (:54)
12-03 18:07:09.470: W/(5047): at $(:442)
12-03 18:07:09.470: W/(5047): at $(:305)
12-03 18:07:09.470: W/(5047): at (:137)
12-03 18:07:09.470: W/(5047): at (:1076)
12-03 18:07:09.470: W/(5047): at $(:569)
12-03 18:07:09.470: W/(5047): at (:856)
12-03 18:07:09.470: W/(5047): Caused by: : Circular redirect to 'http://192.168.1.110:8080/task/'
12-03 18:07:09.470: W/(5047): at (:173)
12-03 18:07:09.470: W/(5047): at (:923)
12-03 18:07:09.470: W/(5047): at (:475)
12-03 18:07:09.470: W/(5047): at (:555)
12-03 18:07:09.470: W/(5047): ... 10 more
package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import .Base64;
import ;
/**
* 为保持web端session超时的问题 将采用20分钟访问一次服务端
*
* @author linhui 2013-12-3上午9:56:11
*/
public class KeepWebSessionService extends Service {
public static final String TAG = "KeepWebSession";
public static final String ACTION = "";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
}
@Override
public void onStart(Intent intent, int startId) {
(TAG, "===keep service start===");
new Thread() {
public void run() {
keepWebSession();
};
}.start();
}
public void keepWebSession() {
// 非ui线程
AsyncHttpClient client = ();
RequestParams rparams = new RequestParams();
String url = new PropertyUtil(this).getUrlBase();
(().getUserCode(), ()
.getPassword());
(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);
("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;.NET CLR 1.1.4322; CIBA; .NET CLR 2.0.50727)");
(url, rparams, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
try {
("success response", response);
JSONObject jsonObj = new JSONObject(response);
if ((jsonObj)) {
(TAG, "=====keep web session=====" + response);
}
} catch (JSONException e) {
(TAG, e + "");
();
}
}
@Override
public void onStart() {
();
(TAG, "onStart");
}
@Override
public void onFinish() {
();
(TAG, "onFinish");
}
@Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2,
Throwable arg3) {
(arg0, arg1, arg2, arg3);
(TAG, "onFailure");
("arg0", arg0 + "");
("arg3", arg3 + "");
}
});
}
@Override
public void onDestroy() {
();
(TAG, "===keep service onDestroy===");
}
}
解决方法:
这个是因为重定向引起的,然后我在加了一个接口,专门用来返回一个json即可。
你可以在服务端返回retur null,或者返回一个json等,只要别重定向就行。
还有一个问题就是,当你报了一次500,或者timetou后,会出现重定向的问题,我怀疑这是location和自己本事的utl冲突导致的,具体的资料我还没有找到,请记得加上下面这句,以免在服务端session超时后,再次调用导致重定向的问题
AsyncHttpClient client = ();
().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);