6

我有一个奇怪的故障,我不能两次拨打同一个网络电话。

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);

    try {
         HttpResponse response = client.execute(post, new BasicHttpContext());

我第一次运行网络调用它工作得很好,数据被返回。我第二次运行网络调用(我在这里运行断点)它到达 HttpResponse 对象,运行网络调用,但随后立即跳转到IOExceptioncatch。

post对象每次都有相同的数据,cookies都包括在内。

我周围没有任何了解服务器(运行drupal)的人,但这似乎是服务器问题。

有人可以解释为什么会发生这种情况吗?为什么我会被禁止第二次取回数据?

为了进一步说明问题,如果我突破响应对象,我可以看到它可能会返回""而不是数据。如果这有帮助的话

05-15 11:22:34.612: E/(1094): ObjectService
05-15 11:22:34.612: E/(1094): org.apache.http.client.ClientProtocolException
05-15 11:22:34.612: E/(1094):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
05-15 11:22:34.612: E/(1094):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-15 11:22:34.612: E/(1094):   at com.fivepoints.service.ObjectService.getObject(ObjectService.java:121)
 05-15 11:22:34.612: E/(1094):  at com.fivepoints.model.team.TeamView$ActivityListTask.doInBackground(TeamView.java:94)
 05-15 11:22:34.612: E/(1094):  at com.fivepoints.model.team.TeamView$ActivityListTask.doInBackground(TeamView.java:1)
05-15 11:22:34.612: E/(1094):   at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-15 11:22:34.612: E/(1094):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-15 11:22:34.612: E/(1094):   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-15 11:22:34.612: E/(1094):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
05-15 11:22:34.612: E/(1094):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
05-15 11:22:34.612: E/(1094):   at java.lang.Thread.run(Thread.java:1019)
05-15 11:22:34.612: E/(1094): Caused by: org.apache.http.client.CircularRedirectException: Circular redirect to 'http://mysite.com/demoObject/_c'
05-15 11:22:34.612: E/(1094):   at org.apache.http.impl.client.DefaultRedirectHandler.getLocationURI(DefaultRedirectHandler.java:173)
05-15 11:22:34.612: E/(1094):   at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:903)
05-15 11:22:34.612: E/(1094):   at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:468)
05-15 11:22:34.612: E/(1094):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-15 11:22:34.612: E/(1094):   ... 10 more
4

1 回答 1

0

起初我记录错误的方式也导致了崩溃,所以我不知道确切的错误是什么。

真正的例外是Caused by: org.apache.http.client.CircularRedirectException因为服务器处理 API 调用的方式

这是来自的答案:

https://stackoverflow.com/a/6699772/727429

HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

于 2012-05-15T15:41:40.467 回答