gpt4 book ai didi

java - android HttpResponse 总是在第二次调用时死掉

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:45:32 26 4
gpt4 key购买 nike

我有一个奇怪的故障,我无法两次进行相同的网络调用。

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

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

我第一次运行网络调用时它工作正常,返回了数据。我第二次运行网络调用(我在此处运行断点)它到达 HttpResponse 对象,运行网络调用,但随后立即跳转到 IOException 捕获。

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

我周围没有任何了解服务器(运行 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

最佳答案

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

真正的异常是 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);

关于java - android HttpResponse 总是在第二次调用时死掉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10603395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com