我正在创建一个网站,它将在计算机屏幕上实时显示驾驶汽车拍摄的图像。我正在通过 Insomnia 发送这样的图片(我还没有服务器):
并且有来自Angular的代码:
video-streaming.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class VideoStreamingService {
constructor(private http: HttpClient) { }
getFiles(url: string): Observable<any> {
return this.http.get(url); // 'http://localhost:8080/api/file/all' anykind
}
}
video-streaming.component.ts
import { Component, OnInit } from '@angular/core';
import { VideoStreamingService } from './video-streaming.service';
@Component({
selector: 'app-video-streaming',
templateUrl: './video-streaming.component.html',
styleUrls: ['./video-streaming.component.css']
})
export class VideoStreamingComponent implements OnInit {
image: any;
constructor(private videoStreamingService: VideoStreamingService) { }
ngOnInit() {
this.getImage('https://192.168.0.102:8080/image');
}
getImage(url: string): void {
this.videoStreamingService.getFiles(url)
.subscribe(image => {
this.image = image;
});
}
}
和HTML 模板:
<img src={{image}}>
我从控制台得到的唯一错误是:
GET https://192.168.0.102:8080/image net::ERR_CONNECTION_TIMED_OUT
我究竟做错了什么?
@更新
我确实改变了线路
this.getImage('https://192.168.0.102:8080/image');
对此:
this.getImage('http://localhost:8080/image');
以及 Insomnia 中的地址:http://localhost:8080/image
错误较多,详情如下。
控制台中的角度错误:
失眠误区: