2
Guys I’m with a test application on Angular 5 and I’m trying to consume the Webservice from the top hat. When performing this attempt the following error appears:
Failed to load https://api.cartolafc.globo.com/mercado/status: The 'Access-Control-Allow-Origin' header has a value 'https://cartolafc.globo.com' that is not Equal to the supplied origin. Origin 'https://localhost:4200' is therefore not allowed access.
I know that for test questions I can simply disable this validation either via plugin or by another option. But in the case of a real application. For example, I will create this application and it will consume the Webservice top hat. How to fix this ?
Service:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Usuario } from '../model/usuario.model';
import { URL_API } from '../util/constantes';
import { Observable } from '../../../node_modules/rxjs';
const httpOptions = {
headers: new HttpHeaders({'Content-Type':'application/json'})
};
@Injectable()
export class UsuarioService {
constructor(private http: HttpClient) { }
public teste2(){
return this.http.get('https://api.cartolafc.globo.com/mercado/status', httpOptions);
}
}
Component:
// O botão no meu HTML chama esse método teste()
public teste(): void{
this.serviceUsuario.teste2()
.subscribe(
(response) => {
console.log("Sucesso");
console.log(response);
},
err => {
console.log("Erro");
console.log(err);
}
)
}
Apparently only the request for the domain https://cartolafc.globo.com/ In this case its application should be in this domain
– Lucas Brogni