Error requesting via POST

0

I am sending information to a page on my server via GET through my application, until it is working normally. However, now I need to send an image in base64 format, I believe that sending via POST works fine, 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 proxy :

"proxies": [{
  "path": "/api",
  "proxyUrl": "https://meu_site.com.br/MeuProjeto/api/"
}]
  

NOTE: The link in the application is correct, I just hid it here for privacy reasons.

In my provider is the call of the 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 correct 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.
?>
    
asked by anonymous 26.11.2017 / 13:32

1 answer

2

There is no HTTP 0 status. This 0 means the return of your request. The second part of the error message says about the URL: NULL . One thing I noticed, was the following excerpt just below exporting the ServiceProvider class:

 urlApi: string = https://meu_site.com.br/MeuProjeto/api/';

In that there is not the first 'before HTTP. I do not know if you have already fixed this, but adjusting, it would look like this:

 urlApi: string = 'https://meu_site.com.br/MeuProjeto/api/';

Another thing that can be is your proxy:

"proxies": [{
  "path": "/api",
  "proxyUrl": "https://meu_site.com.br/MeuProjeto/api/"
}]

Is it not concatenating the proxyUrl with Path? Generating the following URL:

link / api

(this end being '/ api' of the path).

    
29.11.2017 / 14:43