title: Nativescript http php request
body: <p>I am trying to do a simple http request on a remote server in nativescript.This what I have so far:</p>
  
  <pre><code>import { Component, ChangeDetectionStrategy } from '@angular/core';
  import {request} from "http";
  
  
  @Component({
  selector: 'home',
  templateUrl: 'modules/home/home.component.html',
  styleUrls:['modules/home/home.component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush
  })
  
  export class HomeComponent {
  public name: string = "Mark";
  public username: string = "jahflasher";
  public custom_text: string = "This s a custom text field";
  
  public makePOSTRequest() {
  
      request({
          url: "http://www.url.com/nsschoolapp/getHomePage.php",
          method: "POST",
          headers: { "Content-Type": "application/x-www-form-urlencoded" },
          content: JSON.stringify({ Name: this.name, Username: this.username,      Text: this.custom_text })
      }).then(response =&gt; {
          console.log(response.content);
      }).catch(err =&gt; {
          console.log("Error occurred " + err.stack);
      })
  
  }
  
  
       ngOnInit() {
        this.makePOSTRequest();
       }
  }
  </code></pre>
  
  <p>now in the console.log() on the terminal I got this:</p>
  
  <pre><code>    JS: &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
      JS: &lt;html&gt;&lt;head&gt;
      JS: &lt;title&gt;403 Forbidden&lt;/title&gt;
      JS: &lt;/head&gt;&lt;body&gt;
      JS: &lt;h1&gt;Forbidden&lt;/h1&gt;
      JS: &lt;p&gt;You don't have permission to access /nsschoolapp/getHomePage.php
      JS: on this server.&lt;/p&gt;
      JS: &lt;p&gt;Additionally, a 404 Not Found
      JS: error was encountered while trying to use an ErrorDocument to handle the request.&lt;/p&gt;
      JS: &lt;hr&gt;
      JS: &lt;address&gt;Apache Server at www.url.com Port 80&lt;/address&gt;
      JS: &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>now in the php I have this:</p>
  
  <pre><code>&lt;?php 
  
  //http://stackoverflow.com/questions/18382740/cors-not-working-php
  
  if (isset($_SERVER['HTTP_ORIGIN'])) {
      header("Access-Control-Allow-Origin: {$_SERVER['HTTP_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);
  }
  
  
      header('Content-Type: application/json; charset=UTF-8');
      $arr = array('success' =&gt; true,"conent"=&gt; $_POST );
      echo json_encode($arr);
  
  ?&gt;
  </code></pre>
  
  <p>How can I fix this? It appears that I cannot get to the remote file. I do not have permissions.</p>