title: input->post and $_POST are empty in CodeIgniter API calling from Angular 4, what is the right way to make a post request in angular 4
body: <p>This is the first time I'm making a post method request from Angular to CodeIgniter rest API. </p>
  
  <pre><code>postUsertask(Userid,TaskName)
    {
      let body ={
        userid:Userid, taskname:TaskName
      };  
      console.log(body);
      return this.http.post("http://localhost/ci-abc/api/add_task",JSON.stringify(body) )
      .map(res =&gt; res.json());
    }
  </code></pre>
  
  <p>API method in codeigniter:</p>
  
  <pre><code>function add_task_post()
  {
      $obj=json_decode(file_get_contents('php://input'));
      $taskname = $obj-&gt;taskname;
      $userid = $obj-&gt;userid;
      if (!$taskname || !$userid) {
          $this-&gt;response("Enter taskname and userid to add", 400);
      } else
  
          $result = $this-&gt;todo_model-&gt;add_task($taskname, $userid);
  
      if ($result === 0) {
          $this-&gt;response("Task could not be added. Try again.", 404);
      } else {
          $this-&gt;response("success", 200);
      }
  }
  </code></pre>
  
  <p>Had to include to access the data</p>
  
  <blockquote>
    <p>$obj=json_decode(file_get_contents('php://input'));</p>
  </blockquote>
  
  <p>Because the $this->input->post and $_POST were empty and the data recieved from angular was an object so had to be accessed with -> notation. I am curious that this is not the right and ethical way to do this. Also when I didn't put JSON.stringify it gave me Cross Origin Request blocked error so that's why I put it. How should I make POST and PUT request in angular4 to rest API in CodeIgniter?</p>
  
  <p>How do I get rid of CORS error which doesn't let me call the API method, if I can get rid of CORS error then I could also remove <code>JSON.stringify</code> which will send the data as it is and I believe the data should be accessed via <code>input-&gt;post</code> or <code>$_POST</code>.</p>
  
  <p>EDIT 2:
  These sort of errors while making POST PUT and DELETE API call.</p>
  
  <blockquote>
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading
    the remote resource at <a href="http://localhost/ci-abc/api/del_task?taskid=34" rel="nofollow noreferrer">http://localhost/ci-abc/api/del_task?taskid=34</a>.
    (Reason: CORS preflight channel did not succeed)</p>
  </blockquote>