本文主要是介绍项目出错:System.err: java.net.SocketTimeoutException: timeout,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考:
java.net.SocketTimeoutException: Read timed out
Android java.net.SocketTimeoutException: Connection timed out
项目出错:
System.err: java.net.SocketTimeoutException: timeout
出错相关代码:
if (connection.getResponseCode() == 200) { //出错位置InputStream inputStream = connection.getInputStream();baos = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while(-1 != (len = inputStream.read(buffer))){baos.write(buffer,0,len);baos.flush();}return baos.toString("utf-8");}
解决方法:
把socket的超时时间设置的长一些,如下:
connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
改成
connection.setConnectTimeout(60 * 1000);
connection.setReadTimeout(60 * 1000);
这篇关于项目出错:System.err: java.net.SocketTimeoutException: timeout的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!