Bootstrap

http服务器返回文件,http接口返回文件 服务端和客户端

服务端:

@RequestMapping(value = "/lsj", method = {RequestMethod.POST, RequestMethod.GET}, produces = {"text/plain;charset=UTF-8"})

@ResponseBody

public String searchLsjDzzz(String jsonStr,HttpServletResponse httpServletResponse) {

byte[] dzzz = null;

//下载PDF

httpServletResponse.setHeader("Content-Disposition", "attachment;Filename=" + UUID.randomUUID()+".pdf");

OutputStream outputStream = httpServletResponse.getOutputStream();

outputStream.write(dzzz);

outputStream.close();

return "";

}

客户端:

public byte[] requestByGetToByte(String url,String charset){

if (url == null || "".equals(url))

{

log.error("request url is empty.");

return null;

}

HttpClient httpClient = CustomHttpClient.GetHttpClient();

HttpGet get = new HttpGet(url);

get.setHeader("Content-Type", "text/html;charset="+charset);

HttpResponse resp = null;

try

{

// 发起交易

resp = httpClient.execute(get);

// 响应分析

HttpEntity entity = resp.getEntity();

byte[] bytes= EntityUtils.toByteArray(entity);

return bytes;

} catch (ConnectTimeoutException cte){

log.error(cte.getMessage(), cte);

return null;

} catch (SocketTimeoutException cte){

log.error(cte.getMessage(), cte);

return null;

} catch (Exception e){

log.error(e.getMessage(), e);

return null;

}finally{

try {

if(resp!=null){

resp.getEntity().getContent().close();

}

} catch (IllegalStateException e) {

log.error(e.getMessage(), e);

} catch (IOException e) {

log.error(e.getMessage(), e);

}

}

}

来源:https://www.cnblogs.com/zuferj115/p/7580664.html

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;