改造SocketTimeoutException - 上传图片 [英] Retrofit SocketTimeoutException - Uploading Image

查看:599
本文介绍了改造SocketTimeoutException - 上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的改造Android作为我的网络通信。当张贴到我的后端服务器映像,服务器上载的中间,然后改造超时与SocketTimeoutException。

I'm currently using Retrofit for Android as my network communications. When POSTing to my backend server an image, the server is in the middle of the upload and then retrofit "times out" with SocketTimeoutException.

我已经加入了OKhttp库的一些建议,并仍然得到超时。

I have added the OKhttp library as some have suggested and still getting the timeout.

目前IMG大小750KB左右,因为我攀登下来。

The current img sizes are around 750kb because I have scaled them down.

是否有变化以适当的方式,直到用于改装超时的时间量?还是有更好的方式将图像上传到服务器?

Is there an appropriate way to changes the amount of time until a timeout for retrofit? Or is there a better way to upload images to a server?

感谢

推荐答案

也许尝试用<一个改变超时href=\"http://square.github.io/okhttp/javadoc/com/squareup/okhttp/OkHttpClient.html#setReadTimeout%28long,%20java.util.concurrent.TimeUnit%29\"相对=nofollow> setReadTimeout 您OkHttpClient;注意,设置为0表示要永不超时。

Perhaps try changing the timeout with setReadTimeout on your OkHttpClient; note that a setting of 0 indicates to never time out.

奖励:如果你需要帮助找出适当的设置,你可以阅读的字节成功转移从异常超时之前,也找出当前的默认读取超时与<一个href=\"http://square.github.io/okhttp/javadoc/com/squareup/okhttp/OkHttpClient.html#getReadTimeout%28%29\"相对=nofollow> getReadTimeout 。

Bonus: if you need help figuring out an appropriate setting, you can read the bytes successfully transferred before the timeout from the exception, and also find out the current default read timeout with getReadTimeout.

这篇关于改造SocketTimeoutException - 上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆