【问题标题】:how to get json response from the below url如何从以下 url 获取 json 响应
【发布时间】:2017-08-09 15:31:10
【问题描述】:

我有一个返回 json 的 Instagram url (https://www.instagram.com/p/-vSJNUDKKD/?__a=1),但是当我尝试使用 http get 请求调用该 url 时,我得到了整个 html 正文。我在哪里做错了。

  public GetItems(url: string) {
    return this._http.get(url).map((response: Response) => response.json());
  }
  public downloadImage(url: string) {
    var myresult;
    this.GetItems(url + "?__a=1").subscribe((result) => {
      myresult = result;
      console.log(result);

    });

【问题讨论】:

  • 尝试设置content type json
  • 它在尝试时为我抛出了 CORS 问题

标签: json angular http ionic2 instagram-api


【解决方案1】:

当您订阅 http 服务时,您应该有一个 observable。我尝试使用以下代码。似乎对我来说工作正常

getme(url):Observable<any>{
return this.http.get(url)
  .map((res:Response)=>{
    return res.json();
  })

}

 this.http.getme("https://www.instagram.com/p/-vSJNUDKKD/?__a=1").subscribe(
        res=> {

            console.log(res);
        })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    相关资源
    最近更新 更多