我尝试使用get请求从安全API加载mp4视频文件。
在我们的API文档中:
请求(GET):/ cma / contentmanager / getfragment?fragmentid = x 标题:关键 - "授权",价值 - "持票人"
响应(JSON): 内容类型 - 视频/ mp4
我做了以下事情:
public getVideo(url:string): Observable<any> {
const headers = new HttpHeaders({ 'Authorization': 'Bearer ' + this.authenticationService.token, 'Content-Type': 'video/mp4' });
const options = { headers: headers };
return this.http.get(url, options);
}
&#13;
export class MovieComponent implements OnInit {
@ViewChild('videoPlayer') videoplayer: any;
videoUrl: string = '/cma/contentmanager/getfragment?fragmentid=';
videoSource: any;
private loadVideo(id) {
this.requestService.getVideo(this.videoUrl+''+id) // get video for fragment from secure API
.subscribe(data => {
this.videoSource = data;
})
}
}
&#13;
<span (click)="loadVideo(dataItem.Id)">Load {{ dataItem.Name }}</span>
<div class="video">
{{videoSource}}
</div>
&#13;
但视频丢失了。我怎么了?