【发布时间】:2015-06-13 07:41:09
【问题描述】:
我有一个chriskacerguis Rest 服务器,它像 API 服务器一样监听客户端请求。
根据客户端请求,我只想在标头中向客户端发送/响应一些数据。
我的问题是:
如何首先访问客户端标头?
那么如何在 Rest Server 中设置 Header?
这就是我向 REST SERVER 发送请求的方式:
function request_curl($url = NULL) {
$utc = time();
$post = "id=1&CustomerId=1&amount=2450&operatorName=Jondoe&operator=12";
$header_data = array(
"Content-Type: application/json",
"Accept: application/json",
"X-API-KEY:3ecbcb4e62a00d2bc58080218a4376f24a8079e1",
"X-UTC:" . $utc,
);
$ch = curl_init();
$curlOpts = array(
CURLOPT_URL => 'http://domain.com/customapi/api/clientRequest',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $header_data,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_HEADER => 1,
);
curl_setopt_array($ch, $curlOpts);
$answer = curl_exec($ch);
// If there was an error, show it
if (curl_error($ch)) {
die(curl_error($ch));
}
curl_close($ch);
echo '<pre>';
print_r($answer);
echo '</pre>';
}
以下是我的 REST SERVER 函数,它侦听请求并响应标头:
public function clientRequest_post() {
// Getting Post Data
$entityBody = file_get_contents('php://input', 'r');
$this->response($entityBody,200);
//getting header data ,no idea
}
【问题讨论】:
标签: php codeigniter codeigniter-2 codeigniter-restserver