如何从角度7中的任何IP地址获得响应

问题描述 投票:-1回答:1

我想通过向不同的IP地址发送请求来获得任何类型的响应

export class DeviceComponent implements OnInit {

  response: any
  constructor(private deviceService: DeviceService) { }

  ngOnInit() {
    this.deviceService.ping().subscribe(result => {
      console.log(result)
    }, err => {
      console.log(err)
    })
  }
}

export class DeviceService {

  constructor(private http: HttpClient) { }

  ping() {
    const httpHeaders = new HttpHeaders({
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin': '*'
    })

    let me: string = `http://192.168.10.7:100`
    let aw: string = `http://192.168.10.6:100`
    let google: string = `https://www.google.com`
    let youtube: string = `https://www.youtube.com`

    return this.http.get(google, {
      headers: httpHeaders
    })
  }

}

我面临的问题是,当我向youtubegoogle发送请求时,我得到了回复

enter image description here

但是当我向一些local-ip发送请求时,我得到了回复

enter image description here

实际上我的主要目标是得到当地ips的回应

更新

如果我想得到我正在开发这个应用程序的电脑的响应怎么办,让我说我有ip:192.168.9.9。发送请求到我的电脑,但connection refused,然后应该配置什么?

请指导!!!

angular request response angular7
1个回答
0
投票

我们在这里似乎有两个不同的问题:

一方面,您尝试访问由于CORS-Policy(http://www.google.com)而被阻止的see here。 访问http://www.youtube.com时可能相同

另一方面,您尝试访问本地IP。由于不同的原因,连接可能会被拒绝。您的服务器/计算机无法访问或出现其他问题。尝试使用cmd ping 192.168.9.9 ping您的计算机。如果无法访问,请尝试配置防火墙(在两台设备上)。 检查端口是否设置正确,服务器是否正在运行,并且可以从服务器本身访问。 没有额外的信息很难说更多。

© www.soinside.com 2019 - 2024. All rights reserved.