0

I'm using ionic2: my app uses web services APIs and it works correctly in the browser because I enabled cors origin plugin in the browser but I run it to ios simulator I have this error: Response with status: 0 for URL: null in all my api services method I append headers like this:

addPost(token, image, description) {
    var headers = new Headers();
    headers.append('Content-Type', 'applocation/json');
    headers.append('Access-Control-Allow-Origin', '*');

    let postObject = {
        "token": token,
        "image": image,
        "description": description,
    }
    console.log("from service "+ postObject.description);
    console.log("from service "+ postObject.image);
    return this.http.post(this.addPostUrl,postObject,{headers:headers})
    .map((response: Response) => response.json())
}

and I tried send headers like this:

let headers = new Headers( {
        'Access-Control-Allow-Origin' : '*',
        'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
        'Content-Type': 'application/json; charset=UTF-8',
        'Accept': 'application/json',
        'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
    });

in config.xml file I set:

<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

but the same error when running to ios simulator, what should i do to solve this problem?

Al-shimaa Adel
  • 767
  • 1
  • 10
  • 26

1 Answers1

0

I found my issue on Windows 10 and wanted to share. I hope it provides some insight. The UWP on Windows 8.1/10 denies loopback. It has to be set to exempt.

Can't see localhost from UWP app