[Solved] I have an HBase 1.1.2 standalone installation on Ubuntu 14 and I need to retrieve and update data by PHP POST request (I cannot use GET because of length limit) through a REST server. I was going to use a curl PHP object but my problem is I don't understand how to format the request (in JSON or XML) to be submitted in POST at REST server.
Can anyone help me?
Thanks
Let me add my object i would like to use for all the request: getting rows by key and set\create row. My problem is how make $DATA field according different action.
function method($method, $data=NULL, & $http_code, & $response)
{
$ch = curl_init();
if(isset($header))
{
curl_setop(CURLOPT_HTTPHEADER, $header);
}
curl_setopt($ch, CURLOPT_URL, "http://" . $GLOBALS['DBDW']['hostname'] . $GLOBALS['DBDW']['port']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//nuovi
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
'Connection: ' . ( $this->options['alive'] ? 'Keep-Alive' : 'Close' ),
));
// fine nuovi
switch(strtoupper($method)){
case 'DELETE':
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
// i have to set CURLOPT_POSTFIELDS and if yes how?
break;
case 'POST':
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
// how setting CURLOPT_POSTFIELDS and if yes how?
break;
case 'GET':
curl_setopt($curl, CURLOPT_HTTPGET, 1);
// i have to set CURLOPT_POSTFIELDS and if yes how?
break;
}
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->log(LOG_DEBUG, "HTTP code: " . $http_code, __FILE__, __LINE__, __CLASS__);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
if ($response === false)
{
$this->log(LOG_ERR, "HTTP " . $method . " failed on url '" . $url . "'", __FILE__, __LINE__, __CLASS__);
$this->log(LOG_ERR, "cURL error: " . $curl_errno . ":" . $curl_error, __FILE__, __LINE__, __CLASS__);
$http_code=ERR_COMMUNICATION_FAILED;
return false;
}
return true;
}