title: Web API - HTTP Post Request That Includes Header & Body
body: <p>I just got API access for one of the website on the internet, and as a new api developer i got into troubles understanding how should i start and with what, So hope you guys guide me . They don't have Documents or tutorials Yet.</p>
  
  <p>If anyone can give me a small example on how to send Http post request that includes Header and body? As what they are mentioning in the API page:</p>
  
  <blockquote>
    <p>All requests must include an Authorization header with siteid and
    apikey (with a colon in between) and it must match with the siteid and
    apikey in the request body</p>
  </blockquote>
  
  <p>In the body the Parameter content type will be application/json. They have also provided a Base URL.</p>
  
  <p>The response will be as application/json. </p>
  
  <p>What should i do? is the request can be sent using AJAX? or there is PHP code for this? i have been reading a lot about this subject but none enter my head. Really hope you guys help me out . </p>
  
  <p>Please let me know if you need more information so i can provide it to you. </p>
  
  <p><strong>EDIT :</strong> Problem solved and just posting the small editing that i did to the code that was provided in the correct answer that i marked . </p>
  
  <p>Thanks to Mr. Anonymous for the big help that he gave me . His answer was so so close, all what i had to do is just edit his code a little bit and everything went good .</p>
  
  <p>I will list the finial code down bellow in case any other developer had this issue or wanted to do an HTTP request .</p>
  
  <p>First what i did is that i stored the data that i wanted to send over the HTTP in a file with a JSON type :</p>
  
  <pre><code>{
    "criteria": {
      "landmarkId": 181,
      "checkInDate": "2018-02-25",
      "checkOutDate": "2018-02-30"
    }
  }
  </code></pre>
  
  <p>Second thing as what guys can see what Mr. Anonymous posted .</p>
  
  <pre><code>&lt;?php 
  header('Access-Control-Allow-Origin: *');
  
  $SiteID= 'My Site Id';
  $ApiId= 'My Api Id';
  $url = 'Base URL';
  
  // Here i will get the data that i created in Json data type
  $data = file_get_contents("data.json");
  
  // I guess this step in not required cause the data are already in JSON but i had to do it for myself  
  $arrayData = json_decode($data, true);
  
  $ch = curl_init();
  //curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, "$SiteID:$ApiID");
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                              'Content-Type: application/json',
                                              'Connection: Keep-Alive',
                                              'Authorization: $SiteID:$ApiId'
                                              ));
  curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($arrayData)); 
  $result = curl_exec($ch);
  curl_close($ch);  
  print_r($result); 
  
  ?&gt;
  </code></pre>