0
I am sending information to a page on my server via GET
through my application, until then it is working normally. However, now I need to send an image in the format base64
, I believe that sending via POST
work well, but when I try to send I get the error:
Response with status: 0 for URL: null
I’ve even tried to remove the image from the parameters, but I get the same message.
In my configuration I added the proxy
:
"proxies": [{
"path": "/api",
"proxyUrl": "https://meu_site.com.br/MeuProjeto/api/"
}]
NOTE: The link in the application is correct, only hidden here for privacy reasons.
In my provider
is the call of methods get
and post
:
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class ServiceProvider {
urlApi: string = https://meu_site.com.br/MeuProjeto/api/';
constructor(public http: Http) {
}
get(file: string){
console.log("Requisição: " + this.urlApi + file);
return this.http.get(this.urlApi + file).map(res => res.json());
}
post(file: string, params){
let headers = new Headers( {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
'Content-Type': 'Application/x-www-form-urlencoded'
});
return this.http.post("/api" + file, params, {
headers: headers
}).map(res => res.json());
}
}
I call the post method as follows:
this.service.post('minha_pagina.php', params).subscribe(
data =>{
},
err => {
}
);
And then I get the error I mentioned at the beginning of the question. I have tried several ways to fix problems with CORS
, but without success, below I will put my page that is receiving this request:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT');
header('Content-Type: Application/x-www-form-urlencoded');
//Conteúdo da página.
?>
You really need to send this image in Base64 format?
– DiegoAugusto