带有HttpErrorResponse的Nativescript API调用返回

时间:2019-06-10 17:43:07

标签: nativescript nativescript-angular

尝试访问以下API,但在访问它时始终出现错误。该网址是正确的,并且在通过邮递员运行时效果理想。

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width = device-width, initial-scale = 1.0, maximum-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title> Keat </title>
  <link rel="stylesheet" href="style.css" type="text/css">
  <link rel="stylesheet" href="css/fontello.css" type="text/css">
</head>

<body>
  <div class="container">

    <div class="navigation">
      <div class="navigation-l">fgfgfg</div>
      <div class="navigation-r">
        bbbbbb

      </div>
    </div>

    <div class="photo-container">
      <div class="aligned-center">
        <i class="icon-address"></i>
        <h1>Own Way</h1>
        <cite>"Marzenia są tam gdzie jest wolnośc, a my osiągnielismy wolność a nie bezpieczeństwo"</cite>
        <br /><br />

        <cite> ~Jacek Walkiewicz</cite>

      </div>
    </div>
    <div class="articles"></div>
  </div>

仅此调用会返回此错误

let data = this.http.get<any>('http://chargepoints.dft.gov.uk/api/retrieve/registry/lat/53.790224/long/-1.563929/dist/3/format/json');

如果我只是简单地将路径更改为其他api,则可以正常运行。 谁能指出我所缺少的正确方向。

所以我已经更新了AndroidManifest,现在可以正常工作了,但是通过iO,我仍然遇到同样的问题。

1 个答案:

答案 0 :(得分:0)

您需要在HTTP调用中传递内容类型

let httpOptions = { headers: new HttpHeaders(
                    {
                    'Content-Type': 'application/json'
                    })}

 this.http.get<any>(url, httpOptions).subscribe(payloadResponse => {
                        console.log('response received', payloadResponse);                            
                    }, error => {
                      // failed 
                    });