Problem with API query with Ionic

0

I need to do some queries with Ionic 3 on a server whose request must be POST to be returned a JSON. Right away on the first test of creating the query in the browser inspector I get the error:

Failed to load URL:Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

My query function wrote like this:

consulta(): void {
    const headers = new HttpHeaders();
    headers.set('Content-Type', 'application/json; charset=utf-8')
    .set('Access-Control-Allow-Origin', '*');
    this.http.post("URL", { "num_bem": "10000" }, { headers: headers }).subscribe(
        data => {
            console.log(data);
        },
        err => {
            console.log(err);
        }
    );
}

Import I used the following:

import { HttpClient, HttpHeaders } from '@angular/common/http';

I have tried in several ways and I did not get a solution, everything I consulted on the internet has not had a different result from this.

    
asked by anonymous 11.09.2018 / 02:55

0 answers