本文主要是介绍java.io.EOFException at libcore.io.Streams.readAsciiLine(Streams.java:203),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
报错
05-26 16:18:59.720: W/System.err(11399): java.io.EOFException
05-26 16:18:59.720: W/System.err(11399): at libcore.io.Streams.readAsciiLine(Streams.java:203)
05-26 16:18:59.720: W/System.err(11399): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
05-26 16:18:59.720: W/System.err(11399): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
05-26 16:18:59.720: W/System.err(11399): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
05-26 16:18:59.720: W/System.err(11399): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
05-26 16:18:59.720: W/System.err(11399): at com.Base.BaseMethodWebActivity.sendGet(BaseMethodWebActivity.java:2807)
05-26 16:18:59.720: W/System.err(11399): at com.Base.BaseMethodWebActivity.getTopOutStorageInfoAdd(BaseMethodWebActivity.java:856)
05-26 16:18:59.720: W/System.err(11399): at com.main.TYapp2016.topOutPut.OutScaner4Activity$12.run(OutScaner4Activity.java:942)
添加
if (Build.VERSION.SDK != null&& Build.VERSION.SDK_INT > 13) {conn.setRequestProperty("Connection", "close");}
如下
URL realUrl = new URL(urlName);// 打开和URL之间的连接URLConnection conn = realUrl.openConnection();if(isNeedOutTime){conn.setConnectTimeout(TIMEOUT);conn.setReadTimeout(TIMEOUT);isNeedOutTime = false;}// 设置通用的请求属性conn.setRequestProperty("accept", "*/*");conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
// conn.setRequestProperty("connection", "Keep-Alive");conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");if (Build.VERSION.SDK != null&& Build.VERSION.SDK_INT > 13) {conn.setRequestProperty("Connection", "close");}// //TODO 测试代码// PublicMethod.saveCrashInfo2File("网络请求:"+urlName+"\n",PublicMethod.nowContext);// 建立实际的连接conn.connect();// 获取所有响应头字段// Map<String, List<String>> map = conn.getHeaderFields();// 遍历所有的响应头字段// for (String key : map.keySet()) {// Log.i(TAG, "Header : " + key + "--->" + map.get(key));// }// 定义BufferedReader输入流来读取URL的响应in = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;while ((line = in.readLine()) != null) {result += line;}
这篇关于java.io.EOFException at libcore.io.Streams.readAsciiLine(Streams.java:203)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!