Estou com o seguinte problema ao realizar uma requisição utilizando o PUT, meu back-end utiliza PHP.
Meu código PHP:
//inicio PHP
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json; charset=UTF-8');
header('Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS');
//fim PHP
//TS //inicio TS
public put(metodo_api: string, dados) {
console.log(JSON.stringify(dados));
const httpOptions = {
headers: new HttpHeaders({
"Content-Type": "application/json"
})
};
// JSON.stringify(dados)
this._http
.put(
"http://meudominio.com/api/" + metodo_api,
{ id: 1 },
httpOptions
)
.subscribe(
val => {
console.log("PUT call successful value returned in body", val);
},
response => {
console.log("PUT call in error", response);
},
() => {
console.log("The PUT observable is now completed.");
}
);
}
// fim TS
Warning: Access to XMLHttpRequest at 'http://meu.dominio.com/api/clientes' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. requisicoeshttp.service.ts:55
Error: HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http://meudominio.com/api/clientes", ok: false, …} error: ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …} headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)} message: "Http failure response for http://meudominio.com/api/clientes: 0 Unknown Error" name: "HttpErrorResponse" ok: false status: 0 statusText: "Unknown Error" url: "http://meudominio.com/api/clientes"