I/O @Post 请求错误 Android 注释
I/O error for @Post request Android Annotations
我正在为我的应用向 API 发出 Post 请求,当我在 Nexus 5 上执行此操作时一切正常,但当我在 HTC One X 或Samsung Galaxy S3 我收到以下错误:
07-01 11:48:36.605 30101-30251/eu.package.name E/AndroidRuntime﹕ FATAL EXCEPTION: pool-4-thread-3
org.springframework.web.client.ResourceAccessException: I/O error: null; nested exception is java.io.EOFException
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:491)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:415)
at eu.package.name.Rest.RESTClient_.signinFacebook(RESTClient_.java:155)
at eu.package.name.Models.User.userLoginFacebook(User.java:91)
at eu.package.name.Models.User_.access1(User_.java:14)
at eu.package.name.Models.User_.execute(User_.java:65)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:393)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
at com.splunk.mint.network.http.MonitorableHttpURLConnection.getResponseCode(MonitorableHttpURLConnection.java:362)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:54)
at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:80)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:477)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:415)
at eu.package.name.Rest.RESTClient_.signinFacebook(RESTClient_.java:155)
at eu.package.name.Models.User.userLoginFacebook(User.java:91)
at eu.package.name.Models.User_.access1(User_.java:14)
at eu.package.name.Models.User_.execute(User_.java:65)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:393)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
我做的请求是:
@Post("/signin/facebook")
LoginResponse signinFacebook(FacebookLoginRequest facebookLoginRequest);
我已经尝试通过执行以下操作来禁用保持活动状态:
restClient.setHeader("Connection", "Close");
LoginResponse loginResponse = restClient.signinFacebook(facebookLoginRequest);
我建议试用 okhttp 客户端:
@Rest(rootUrl = "url", requestFactory = OkHttpClientHttpRequestFactory.class)
这应该可以解决许多与标准 Android http 客户端相关的问题,包括这个问题。请注意 OkHttpClientHttpRequestFactory
仅适用于 Spring Android 2.0.
编辑: 您必须声明以下依赖项才能使用 OkHttpClientHttpRequestFactory
:
compile "org.springframework.android:spring-android-rest-template:2.0.0.M2"
compile "com.squareup.okhttp:okhttp:2.4.0"
compile "com.squareup.okhttp:okhttp-urlconnection:2.4.0"
我正在为我的应用向 API 发出 Post 请求,当我在 Nexus 5 上执行此操作时一切正常,但当我在 HTC One X 或Samsung Galaxy S3 我收到以下错误:
07-01 11:48:36.605 30101-30251/eu.package.name E/AndroidRuntime﹕ FATAL EXCEPTION: pool-4-thread-3
org.springframework.web.client.ResourceAccessException: I/O error: null; nested exception is java.io.EOFException
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:491)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:415)
at eu.package.name.Rest.RESTClient_.signinFacebook(RESTClient_.java:155)
at eu.package.name.Models.User.userLoginFacebook(User.java:91)
at eu.package.name.Models.User_.access1(User_.java:14)
at eu.package.name.Models.User_.execute(User_.java:65)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:393)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
at com.splunk.mint.network.http.MonitorableHttpURLConnection.getResponseCode(MonitorableHttpURLConnection.java:362)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:54)
at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:80)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:477)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:415)
at eu.package.name.Rest.RESTClient_.signinFacebook(RESTClient_.java:155)
at eu.package.name.Models.User.userLoginFacebook(User.java:91)
at eu.package.name.Models.User_.access1(User_.java:14)
at eu.package.name.Models.User_.execute(User_.java:65)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:393)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
我做的请求是:
@Post("/signin/facebook")
LoginResponse signinFacebook(FacebookLoginRequest facebookLoginRequest);
我已经尝试通过执行以下操作来禁用保持活动状态:
restClient.setHeader("Connection", "Close");
LoginResponse loginResponse = restClient.signinFacebook(facebookLoginRequest);
我建议试用 okhttp 客户端:
@Rest(rootUrl = "url", requestFactory = OkHttpClientHttpRequestFactory.class)
这应该可以解决许多与标准 Android http 客户端相关的问题,包括这个问题。请注意 OkHttpClientHttpRequestFactory
仅适用于 Spring Android 2.0.
编辑: 您必须声明以下依赖项才能使用 OkHttpClientHttpRequestFactory
:
compile "org.springframework.android:spring-android-rest-template:2.0.0.M2"
compile "com.squareup.okhttp:okhttp:2.4.0"
compile "com.squareup.okhttp:okhttp-urlconnection:2.4.0"