0
我試圖返回一個使用春季啓動mp4視頻。 問題是,當我使用localhsot訪問控制方法:本地主機返回標題和內容不同於127.0.0.1或本地IP
http://localhsot:8080/files/videos/mission0.mp4
它返回:
Content-Type →video/mp4
Date →Thu, 11 Aug 2016 17:41:30 GMT
Transfer-Encoding →chunked
X-Application-Context →application
,並在瀏覽器中, 視頻播放,但我在使用127.0.0.1或本地IP而不是本地主機它返回:
Cache-Control →no-cache
Connection →close
Pragma →no-cache
並且沒有視頻返回。
這裏是我的代碼:
@RequestMapping(value="/videos/{fileName:.+}")
public void getVideo(HttpServletResponse response, @PathVariable("fileName") String fileName) {
byte[] video = fileService.getFileBytes(videoDir, fileName);
ByteInputStream videoStream = new ByteInputStream(video, video.length);
try {
response.setHeader("Content-Type", "video/mp4");
IOUtils.copy(videoStream, response.getOutputStream());
} catch (IOException e) {
throw new InternalServerErrorException("Error while rendering the video");
}
}
當進行請求時,環回必須作爲localhost被轉換爲環回IP。 –
其工作正常,和其他api終點(返回json或圖像)工作正常。 – Ward
@ShawnClark你可以試試你機器上的代碼嗎? – Ward