我尝试使用HTTP get请求检查服务器上是否存在pdf文件,因为我正在测试服务器响应返回的状态码是否不同于200,问题是我总是得到状态码200和statusText "OK“。
这是我的Service类
getPdf(year: number,type: number, num: number): boolean{
this.http.get('http://localhost:4200/app/pdfs/'+year+'/'+type+'/'+num+'.pdf')
.subscribe(data => console.log(data));
return true;
}在我的组件中,我有这样的代码:
ngOnInit(){
this.pdfService.getPdf(2016,71015,1275);
}这就是我在Chrome开发工具控制台中得到的结果

你知道为什么会发生这种情况吗?如果这种方法不适用,我如何检查文件的存在?
发布于 2016-11-23 21:48:10
我认为您的服务器正在将对未找到的资产的部分或全部请求重定向到您的主页。对于单页面应用程序来说,这是很常见的。您需要更新服务器配置,使其至少为某些文件夹返回not found响应。
https://stackoverflow.com/questions/40765292
复制相似问题