【发布时间】:2017-09-08 14:49:38
【问题描述】:
我正在尝试使用 Angular Http 从我的 Ionic 应用程序中使用 Web 服务。我正在关注 Josh Morony Example -> https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/,但是当我在 url 中使用 IP 地址时收到以下错误:
ERROR Object { _body: error, status: 0, ok: false, statusText: "", 标头:对象,类型:3,url:null }
这是我的 ts 代码 -> home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
posts: any;
url: string = 'http://200.33.191.161:9090/reservationsapi/31922904?idHotel=2
';
constructor(public navCtrl: NavController, public http: Http) {
this.http.get(this.url).map(res => res.json()).subscribe(data => {
this.posts = data.data.children;
});
console.log(this.posts);
}
}
问题是当我使用 IP 地址时,如果我使用示例的 url:https://www.reddit.com/r/gifs/top/.json?limit=10&sort=hot 工作正常。 任何想法或cmets。提前谢谢!
【问题讨论】:
-
ip 不正确,很可能是 elb ip,我猜好像你在 post man 中尝试它没有响应,所以 Angular 不应该受到责备
-
嗨 Rahul,我在 Postman 中尝试过,它适用于 GET,但我不知道为什么在 Angular 中不起作用!
-
没有回复我,你可能给了一个 diff url
-
嗨 Rahul,你是对的,当这个 IP 地址有问题时,我已经报告了,请稍后再试看看问题,请注意我更新了 URL。再次感谢您的 cmets!
-
嗨,我刚刚尝试使用 Postman 和 PHP - CURL,它工作正常,我得到了一个 json 对象,但我仍然收到与 Ionic2 或 Angular 2、anu cmets 相同的错误消息?