@RequestMapping("/bbb")
public String text(HttpServletRequest re, HttpServletResponse rs) {
CloseableHttpClient httpClient = null;
/*解决信任SSL证书(PKIX path building failed问题)
*/
try {
SSLContext sslContext = SSLContextBuilder.create().useProtocol(SSLConnectionSocketFactory.SSL)
.loadTrustMaterial((x, y) -> true).build();
RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build();
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).setSSLContext(sslContext)
.setSSLHostnameVerifier((x, y) -> true).build();
} catch (Exception e) {
e.printStackTrace();
}
String flag = "0";
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader(new BasicHeader("Cookie", Cookie));
// response 对象
CloseableHttpResponse response = null;
response = httpClient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
//现在用流来接受entity
InputStream in=**entity.getContent();**
int count = 0;
//下面进行写入字节
while (count == 0) {
count = Integer.parseInt(""+entity.getContentLength());//in.available();
}
byte[] bytes = new byte[count];
int readCount = 0; // 已经成功读取的字节的个数
while (readCount <= count) {
if(readCount == count)break;
readCount += in.read(bytes, readCount, count - readCount);
}
OutputStream out=null;
rs.setContentType("video/mp4");
out = rs.getOutputStream();
out.write(bytes);
out.flush();
out.close();
}
//别忘记关闭连接 省略不写了
}
前端:
<video width="1120" height="540" controls="controls" id= "video" preload="auto">
<source src= "../bbb.do" type-"video/mp4" >
</video>
最后完美解决