我正在尝试使用随附的SyncClient创建连接

https://github.com/loopj/android-async-http

我无法连接到我的Web服务,它显示以下日志

12-05 19:54:45.397: W/System.err(3836): org.apache.http.client.ClientProtocolException
12-05 19:54:45.397: W/System.err(3836):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
12-05 19:54:45.397: W/System.err(3836):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-05 19:54:45.397: W/System.err(3836):     at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:75)
12-05 19:54:45.397: W/System.err(3836):     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:94)
12-05 19:54:45.397: W/System.err(3836):     at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:56)
12-05 19:54:45.397: W/System.err(3836):     at com.loopj.android.http.SyncHttpClient.sendRequest(SyncHttpClient.java:66)
12-05 19:54:45.407: W/System.err(3836):     at com.loopj.android.http.AsyncHttpClient.get(AsyncHttpClient.java:340)
12-05 19:54:45.407: W/System.err(3836):     at com.loopj.android.http.AsyncHttpClient.get(AsyncHttpClient.java:329)
12-05 19:54:45.407: W/System.err(3836):     at net.connectedu.service.AlarmService.checkAppStatus(AlarmService.java:151)
12-05 19:54:45.407: W/System.err(3836):     at net.connectedu.service.AlarmService.doWakefulWork(AlarmService.java:146)
12-05 19:54:45.407: W/System.err(3836):     at com.commonsware.cwac.wakeful.WakefulIntentService.onHandleIntent(WakefulIntentService.java:108)
12-05 19:54:45.407: W/System.err(3836):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
12-05 19:54:45.418: W/System.err(3836):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 19:54:45.418: W/System.err(3836):     at android.os.Looper.loop(Looper.java:137)
12-05 19:54:45.418: W/System.err(3836):     at android.os.HandlerThread.run(HandlerThread.java:60)
12-05 19:54:45.418: W/System.err(3836): Caused by: org.apache.http.client.CircularRedirectException: Circular redirect to 'https://localhost/api/get_logs/lalith/'
12-05 19:54:45.427: W/System.err(3836):     at org.apache.http.impl.client.DefaultRedirectHandler.getLocationURI(DefaultRedirectHandler.java:173)
12-05 19:54:45.427: W/System.err(3836):     at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:923)
12-05 19:54:45.437: W/System.err(3836):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:475)
12-05 19:54:45.437: W/System.err(3836):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-05 19:54:45.437: W/System.err(3836):     ... 14 more


可能的原因是什么? loopj中的同步库工作正常吗?

最佳答案

我刚刚发现如何在loopj-android http lib中使用同步库:以下是示例。我能够在第一次触发警报时获得响应,但是在下次安排警报接收器时会得到上面的代码。希望找到一些答案:(

String content = ConnectionManager.getSyncClient.get("http://www.google.com");


下次请求到来时,我会收到上面的异常。 :(

我在库中发现错误,它不允许循环重定向。我想,会有其他人遇到类似的问题。我发现这篇文章很有帮助,

Avoid Circular Redirect using HttpClient 4.1.1

08-07 02:16