You are here

function KalturaClientBase::do_post_request in Kaltura 5

Same name and namespace in other branches
  1. 6 kaltura_client/kaltura_client_base.php \KalturaClientBase::do_post_request()
1 call to KalturaClientBase::do_post_request()
KalturaClientBase::hit in kaltura_client/kaltura_client_base.php

File

kaltura_client/kaltura_client_base.php, line 86

Class

KalturaClientBase

Code

function do_post_request($url, $data, $optional_headers = null) {
  if (!function_exists('fsockopen')) {
    return null;
  }
  $start = strpos($url, '//') + 2;
  $end = strpos($url, '/', $start);
  $host = substr($url, $start, $end - $start);
  $domain = substr($url, $end);
  $fp = fsockopen($host, 80);
  if (!$fp) {
    return null;
  }
  fputs($fp, "POST {$domain} HTTP/1.1\n");
  fputs($fp, "Host: {$host}\n");
  if ($optional_headers) {
    fputs($fp, $optional_headers);
  }
  fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
  fputs($fp, "Content-length: " . strlen($data) . "\n\n");
  fputs($fp, "{$data}\n\n");
  $response = "";
  while (!feof($fp)) {
    $response .= fread($fp, 32768);
  }
  $pos = strpos($response, "\r\n\r\n");
  if ($pos) {
    $response = substr($response, $pos + 4);
  }
  else {
    $response = "";
  }
  fclose($fp);
  return $response;
}