-2

Trying to access the following API but keep getting an error when access it. The url is correct and works perfectly when run through postman.

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

Just this call alone returns this error

CONSOLE ERROR
file:///app/tns_modules/@angular/core/bundles/core.umd.js:15769:28: 
ERROR {
    "headers": {
    "normalizedNames": {},
    "lazyUpdate": null,
    "headers": {}
},
"status": 0,
"statusText": "Unknown Error",
"url":"http://chargepoints.dft.gov.uk/api/retrieve/registry/lat/53.790224/long/-1.563929/dist/3",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure response for http://chargepoints.dft.gov.uk/api/retrieve/registry/lat/53.790224/long/-1.563929/dist/3: 0 Unknown Error",
"error": {
"line": 1298,
"column": 38,
"sourceURL": "file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js",
"originalStack": "ZoneAwareError@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:1298:38\nfile:///app/tns_modules/tns-core-modules/http/http-request/http-request.js:97:37\nUIApplicationMain@[native code]\n_start@file:///app/tns_modules/tns-core-modules/application/application.js:275:26\nrun@file:///app/tns_mo<…>

If I simply change the path to a different api it works absolutely fine. Can anyone point me in the right direction as to what i'm missing.

So i've updated the AndroidManifest and that works fine now, however via iOs I still get the same problem.

coodey
  • 35
  • 3
  • 1
    CORS issue probably – David Jun 10 '19 at 18:32
  • what is this `this.http.get[any]` about? does that even work? – Reactgular Jun 10 '19 at 18:54
  • @Reactgular There's a `nb` about the return type... don't know why, but seems OP cannot write `` ?? – AT82 Jun 10 '19 at 19:03
  • @AJT_82 thank you. The OP was using `
    ` tags in the markdown editor.
    – Reactgular Jun 10 '19 at 19:05
  • @Reactgular Yeah, I saw. Was just editing the post when you edited it :D – AT82 Jun 10 '19 at 19:05
  • 1
    Possible duplicate of [Nativescript: HTTP failure response for unknown URL](https://stackoverflow.com/questions/54018049/nativescript-http-failure-response-for-unknown-url) / [Http request fail on NativeScript Angular](https://stackoverflow.com/questions/48012342/http-request-fail-on-nativescript-angular) – Manoj Jun 10 '19 at 19:21
  • I am using just for some reason couldn't get it in the editor - kept stripping it out – coodey Jun 10 '19 at 21:40
  • Thank's Manoj. Working in both iOs and android from both of those articles. – coodey Jun 10 '19 at 22:20

1 Answers1

0

you need pass content type in your HTTP call

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

 this.http.get<any>(url, httpOptions).subscribe(payloadResponse => {
                        console.log('response received', payloadResponse);                            
                    }, error => {
                      // failed 
                    });
Sarjerao Ghadage
  • 1,420
  • 16
  • 31