I can not send the .json file

1

I'm trying to send a .json file created within Angular to a server, and gives this error in response:

  

"A JSONObject text must begin with '{' at 1 [character 2 line 1]", object_or_array: "object", error_info: "This error came from the org.json reference parser.", validate: false} "

You're just going to URL, without JSON, by the way. Here is the code, made in angular:

var json={
      usuario : this.nome,
      senha : this.senha
  };

  var myJson=JSON.stringify(json);


  console.log(json);

  return this.http.post(this.url,JSON.stringify(json))
  .map(res=> res.json())
  .subscribe(data =>{
    console.log(data);
});
    
asked by anonymous 19.12.2018 / 00:59

1 answer

1

I solved the problem, I just added in the webservice within your php the following codes:

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
    
20.12.2018 / 01:00