【发布时间】:2016-05-20 07:31:05
【问题描述】:
我想将 http 标头发送到 Api 并获得 json 响应。
我在书本表中有所有书籍详细信息,我想获取所有书籍。
但我有 5 个 http 标头可以访问它们。
Client-Service,Auth-Key,Content-Type,User-ID,Authorization
获取详细信息的网址:
http://127.0.0.1/RestApi/index.php/book/
控制器代码:
public function index() {
$method = $_SERVER['REQUEST_METHOD'];
if ($method != 'GET') {
json_output(400, array('status' => 400, 'message' => 'Bad request.'));
} else {
$check_auth_client = $this->MyModel->check_auth_client();
if ($check_auth_client == true) {
$response = $this->MyModel->auth();
if ($response['status'] == 200) {
$resp = $this->MyModel->book_all_data();
json_output($response['status'], $resp);
}
}
}
}
型号代码:
public function book_all_data()
{
return $this->db->select('id,title,author')->from('books')->order_by('id','desc')->get()->result();
}
我想通过点击按钮访问,但是如何将 http 标头发送到 rest api 页面并使用 codeigniter 获取所有数据?
【问题讨论】:
-
使用工程师先生提到的curl
标签: php json codeigniter api