protected function httpRequestWithoutCurl($action, $data, $method = 'POST', $options = [])
{
if ($this->fileUpload === true) {
$this->fileUpload = false;
throw new Sailthru_Client_Exception('cURL extension is required for the request with file upload', Sailthru_Client_Exception::CODE_GENERAL);
}
$url = $this->api_uri . "/" . $action;
$params = ['http' => ['method' => $method, 'ignore_errors' => true]];
if ($method == 'POST') {
$params['http']['content'] = is_array($data) ? http_build_query($data, '', '&') : $data;
} else {
$url .= '?' . http_build_query($data, '', '&');
}
$params['http']['header'] = "User-Agent: {$this->user_agent_string}\nContent-Type: application/x-www-form-urlencoded";
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Sailthru_Client_Exception("Unable to open stream: {$url}", Sailthru_Client_Exception::CODE_GENERAL);
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Sailthru_Client_Exception("No response received from stream: {$url}", Sailthru_Client_Exception::CODE_RESPONSE_EMPTY);
}
return $response;
}