我想使用HttpURLConnection向Servlet请求图片,但是返回的数据就表头一些东西,我的图片哪去了?? Servlet代码:
OutputStream os = response.getOutputStream();
try{
long start_time = System.currentTimeMillis(); //读取图片
Photo photo = FileManager.readPhoto(path,name);
//存储大图数据
os.write(photo.getFilebyte());
os.flush();
os.close(); response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer(); long end_time = System.currentTimeMillis();
LogUtil.log("查询大图"+photo.getFilebyte().length+"耗时"+(end_time-start_time), LogUtil.MSG); }catch(Exception e){
LogUtil.log("查询大图异常"+e,LogUtil.ERROR,"",""); } Client代码: String ls_url = "http://10.99.103.75:9080/xhphoto/servlet/PhotoServer";
//连接服务器
HttpURLConnection l_connect = (HttpURLConnection)new URL(ls_url).openConnection();
l_connect.setDefaultUseCaches(false);
l_connect.setRequestMethod("POST");
l_connect.setDoInput(true);
l_connect.setDoOutput(true);//提交数据
OutputStream l_output = l_connect.getOutputStream();
l_output.write("20081025/picture;LOC827dc83b-e00e-483f-9f2f-dd6b7904317e".getBytes());
l_output.flush();
InputStream is = l_connect.getInputStream();
byte[] b = new byte[is.available()];
String ls_return = "";
while(is.read(b)>0){
ls_return += new String(b);
} 我是不是有参数没写,请高手帮忙指点啊。
OutputStream os = response.getOutputStream();
try{
long start_time = System.currentTimeMillis(); //读取图片
Photo photo = FileManager.readPhoto(path,name);
//存储大图数据
os.write(photo.getFilebyte());
os.flush();
os.close(); response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer(); long end_time = System.currentTimeMillis();
LogUtil.log("查询大图"+photo.getFilebyte().length+"耗时"+(end_time-start_time), LogUtil.MSG); }catch(Exception e){
LogUtil.log("查询大图异常"+e,LogUtil.ERROR,"",""); } Client代码: String ls_url = "http://10.99.103.75:9080/xhphoto/servlet/PhotoServer";
//连接服务器
HttpURLConnection l_connect = (HttpURLConnection)new URL(ls_url).openConnection();
l_connect.setDefaultUseCaches(false);
l_connect.setRequestMethod("POST");
l_connect.setDoInput(true);
l_connect.setDoOutput(true);//提交数据
OutputStream l_output = l_connect.getOutputStream();
l_output.write("20081025/picture;LOC827dc83b-e00e-483f-9f2f-dd6b7904317e".getBytes());
l_output.flush();
InputStream is = l_connect.getInputStream();
byte[] b = new byte[is.available()];
String ls_return = "";
while(is.read(b)>0){
ls_return += new String(b);
} 我是不是有参数没写,请高手帮忙指点啊。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货