Why does this/any HTTP request rejects?

Hi there,

so … My problem is that on any request I send, the error handler gets rejected.

This is the set up:

import { Injectable } from '@angular/core';
import { Http, HttpModule } from '@angular/http';

@NgModule({
  ...
  imports: [
    ...
    HttpModule
    ...
  ],
  ...
})
export class AppModule {}


@Injectable()
export class MyClass {
  constructor(private http: Http,){}

  myFunc(): {
    this.http.get('https://anycoindirect.eu/api/public/coins').subscribe(data => {
      debugger;
    }, error => {
      debugger;
    });
  }
}

The error-value I get is:

image

But why?

ionic serve'ing with Ionic 3.10.3, Cordova 7.0.1 and Npm 3.10.10.

Thanks for any help!

This is what I get from the network protocoll:

XMLHttpRequest cannot load https://anycoindirect.eu/api/public/coins. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

What does this mean? What to do?

So I changed the GET-request to this:

this.http.get(’/api/public/coins’)

… and added a proxies field to ionic.config.json, like in good’ol Ionic 1 days:

{
  "name": "MyApp",
  "app_id": "",
  ...
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "https://anycoindirect.eu/api"
    }
  ]
}

But even this didn’t help. Only the error message changed. The error object shows a 404 error now, because it trys to find the api on localhost:

image

Hmm … why don’t fit the set proxy? Do I need a proxy? I think, if I use ionic serve I’ll have to set a proxy, right? I don’t get it, I just want this fu**nky response from the api :frowning:

I don’t know why … Since I tried ionic serve -l I don’t get the 404 errors any more. It’s 502 now. If I set a wrong proxyUrl it turns to error no. 500. All errors are from the proxy and shows in _body field of the error the response with detailed error information.

So I switched the proxyUrl again to the correct url. And now … error 200! Finally :smiley:

So the problem is solved and I don’t really know, why.

Maybe this helps someone :slight_smile:

hi can you show some examples? what if the files is html type… how do you do it? what if it has children path