Files
crm.clientright.ru/includes/SalesPlatform/HTTPClient/SPHTTPClient.php

56 lines
1.6 KiB
PHP
Executable File

<?php
require_once('curl_http_client.php');
class SPHTTPClient extends Curl_HTTP_Client {
var $_serviceurl = '';
function __construct($url) {
if(!function_exists('curl_exec')) {
die('SPHTTPClient: Curl extension not enabled!');
}
parent::__construct();
$this->_serviceurl = $url;
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$this->set_user_agent($useragent);
// Escape SSL certificate hostname verification
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
}
function doPost($headers, $postdata = false, $decodeResponseJSON = false, $timeout = 20) {
$this->set_headers($headers);
if($postdata === false) $postdata = Array();
$resdata = $this->send_post_data($this->_serviceurl, $postdata, null, $timeout);
if($resdata && $decodeResponseJSON) $resdata = $this->__jsondecode($resdata);
return $resdata;
}
function doGet($suburl='', $getdata=false, $decodeResponseJSON=false, $timeout=20) {
if($getdata === false) $getdata = Array();
$queryString = '';
foreach($getdata as $key=>$value) {
$queryString .= '&' . urlencode($key)."=".urlencode($value);
}
$resdata = $this->fetch_url("$this->_serviceurl$suburl?$queryString", null, $timeout);
if($resdata && $decodeResponseJSON) $resdata = $this->__jsondecode($resdata);
return $resdata;
}
function __jsondecode($indata) {
return json_decode($indata,true);
}
function __jsonencode($indata) {
return json_encode($indata);
}
function set_headers($headers) {
if(is_array($headers)) {
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
}
}
}
?>