android http 报java.io.EOFException
代码如下:
URL url = new URL(urlString);
HttpURLConnection conn;
conn = (HttpURLConnection) url.openConnection();
// 建立连接
conn.setRequestMethod("GET");// 设置请求方式
conn.setConnectTimeout(5000);// 设置超时时间
// conn.setReadTimeout(5000);
input = conn.getInputStream();
int all = input.available();
System.out.println("---------------"+all);
// 将内容写入byte数组
String webpage = "";
while (all > 0) {
byte[] b = new byte[all];
input.read(b);
webpage = new String(b);
all = input.available();
}
input.close();
return webpage;
通过以上代码进行http请求,然后发现有的请求没有正常返回,报了java.io.EOFException的异常,有的请求正常返回了,而且没有正常返回的url,放到浏览器中也是有返回值的,最后换了post方式还是不行,谁遇见过?