title: Sending json data to backend via HTTP POST in Ionic 4 not working. [Notice: Trying to get property of non-object]
body: <p>I try to send http request via http post in Ionic 4 to my PHP backend through URL<code>http://myexamplehost#1.com/api</code> and it gives me back <code>Notice : trying to get property of non object...</code>.</p>
  
  <p>When i send my json data through URL <code>http://myexamplehost#1.com/api</code> via postman it works just fine. I'm guessing my json data sent via http post in Ionic 4 is somehow wrong. </p>
  
  <p>So i try to send my json data through my other URL <code>https://myexamplehost#2.com/api</code> via http post in Ionic 4 and long behold it works just fine.  </p>
  
  <p>Here's what the json i sent via postman :</p>
  
  <pre><code>{
    "id": "",
    "date": "2019-09-09",
    "name": "jason"
  }
  </code></pre>
  
  <p>And here's what i sent via http post in Ionic 4 page.ts:</p>
  
  <pre><code>  mydata: Idata = {
      id:string;
      date:string;
      name:string
    }
  
     saveData(){
       this.dk.insertData(this.mydata).subscribe((result:any)=&gt;{
         console.log(result['_body']);
       });
  
    }
  </code></pre>
  
  <p>Here's what the service method look like :</p>
  
  <pre><code>insertData(data:Idata){
      return this.http.post(this.configUrl+'?ins=true',data,{
        headers: { 'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT'
      }
      });
  </code></pre>
  
  <p>Here's what the backend look like :</p>
  
  <pre><code>if (isset($_SERVER['HTTP_ORIGIN'])) {
          header("Access-Control-Allow-Origin: *");
          header('Access-Control-Allow-Credentials: true');
          header('Access-Control-Max-Age: 86400');    // cache for 1 day
      }
  
      // Access-Control headers are received during OPTIONS requests
      if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  
          if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
              header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
  
          if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
              header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  
          exit(0);
      }
  
  $postdata = file_get_contents("php://input");
  $request = json_decode($postdata);
      print_r(json_encode($request));
  //    echo json_encode($request-&gt;name."-".$request-&gt;date);
  //    echo json_encode($request-&gt;tgl);
      $result = $obj-&gt;insData("example_tb","null,'".date('Y-m-d',strtotime($request-&gt;date))."','".$request-&gt;name."'");
  </code></pre>
  
  <p>So what i really want to know is that is it a CORS issues or is it a code issues in my situation right there? Because i do get an error message of <code>origin has been blocked by CORS policy</code> in a console though. How do i fix this issues?</p>