调用setRequestMethod("get")方法,弹出异常
各位大侠,我想用Http方式获取网络上一张图片
HttpURLConnection httpConn; try { URL url=new URL(path); httpConn = (HttpURLConnection)url.openConnection(); httpConn.setConnectTimeout(5*1000); httpConn.setRequestMethod("get"); int code=httpConn.getResponseCode(); Log.d(tag,"Responsecode is "+code); InputStream ipStream=httpConn.getInputStream(); int len=-1; ByteArrayOutputStream otStream=new ByteArrayOutputStream(); while((len=ipStream.read(bt))!=-1){ otStream.write(bt, 0, len); } ipStream.close(); otStream.close(); return otStream.toByteArray(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Log.d(tag, "IOException.."+e1.toString()); }