我正在使用Retrofit 1.9.0 for android中的RESTclient,它得到的错误就像我在下面发布的那样:
retrofit.RetrofitError: sendto failed: EPIPE (Broken pipe)
04-03 20:18:51.995 8634-8634/up.tech.opener W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
04-03 20:18:51.995 8634-8634/up.tech.opener W/System.err: at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
04-03 20:18:51.995 8634-8634/up.tech.opener W/System.err: at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
04-03 20:18:51.995 8634-8634/up.tech.opener W/System.err: at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
04-03 20:18:51.995 8634-8634/up.tech.opener W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-03 20:18:51.996 8634-8634/up.tech.opener W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-03 20:18:51.996 8634-8634/up.tech.opener W/System.err: at retrofit.Platform$Android$2$1.run(Platform.java:142)
04-03 20:18:51.996 8634-8634/up.tech.opener W/System.err: at java.lang.Thread.run(Thread.java:838)
04-03 20:18:51.996 8634-8634/up.tech.opener W/System.err: Caused by: java.net.SocketException: sendto failed: EPIPE (Broken pipe)
04-03 20:18:51.997 8634-8634/up.tech.opener W/System.err: at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:550)
04-03 20:18:51.997 8634-8634/up.tech.opener W/System.err: at libcore.io.IoBridge.sendto(IoBridge.java:519)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at java.net.PlainSocketImpl.write(PlainSocketImpl.java:511)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at java.io.OutputStream.write(OutputStream.java:82)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at libcore.net.http.HttpEngine.writeRequestHeaders(HttpEngine.java:659)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:808)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:293)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:505)
04-03 20:18:51.998 8634-8634/up.tech.opener W/System.err: at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73)
04-03 20:18:51.999 8634-8634/up.tech.opener W/System.err: at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
04-03 20:18:51.999 8634-8634/up.tech.opener W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
04-03 20:18:51.999 8634-8634/up.tech.opener W/System.err: ... 7 more
有人知道如何解决这个问题吗?
答案 0 :(得分:1)
只是为了确保您的配置正确
检查您是否已将所有必需的权限添加到AndroidManifest.xml
(EPIPE经常因缺少权限而发生)
答案 1 :(得分:0)
脚本可能会卡在代码中的某个位置,因此不会发布响应,而服务器会关闭套接字。
增加超时值
okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);
在您的gradle上添加
compile 'com.squareup.okhttp:okhttp:2.0.0'
Compile 'come.scrap.okhttp:okhttp-urlconnection:2.0.0'
答案 2 :(得分:0)
如果未在翻新助手中设置端口,例如:http://172.51.65.62
retforit尝试连接到:http://172.51.65.62:80
现在如果使用其他任何端口80,您将收到此错误
要修复此错误更改IP或地址,例如:http://172.51.65.62:8256