通过获取数据从 Post 数据中获取 URI

Fetch URI from Post Data through Get Data

显示 1 个带有 2 个按钮的文本字段 - Post,获取。在文本字段中输入一个数字。单击 Post,创建一个从 1 到该数字的数组。 Post 这个数组在 URL。显示 Post.On 单击 Get 的响应,从 Post 返回的 URL 中获取数据并显示它。

urlPost = 'https://api.myjson.com/bins';
clist: number[] = [];
strData: string = '';
S1: String = '';
ntext: number;
constructor(private netService: NetService) {}

postData() {
    for (var i = 1; i <= this.ntext; i++) {
        this.clist.push(i);
    }
    this.netService.postData(this.urlPost, this.clist)
        .subscribe(postresp => {
            this.strData = JSON.stringify(postresp);
        });
}

getData() {
    this.netService.getData(this.strData.Uri)
        .subscribe(resp => {
            this.strData = JSON.stringify(resp);
        });
}

这条线路需要改进。

this.netService.getData(this.strData.Uri)

As I understand your question, you simply have a problem with parsing a response from your postData(). So, just refer to the following -

postData() {
    for (var i = 1; i <= this.ntext; i++) {
        this.clist.push(i);
    }
    this.netService.postData(this.urlPost, this.clist)
        .subscribe(postresp => {
            this.S1 = postresp['uri'];    // get URL here
        });
}

getData() {
    this.netService.getData(this.S1)      // use it here
        .subscribe(resp => {
            this.strData = JSON.stringify(resp);
        });
}

看到它工作 here.