已经用列名“ keys
”创建了表“ key
”,其值为
'keys@345
',然后在我的控制器(Codeigniter 3)文件中设置Rest_controller,并将Curl.php库保留在库文件夹中。
使用curl规则时,从我的浏览器访问URL时出现“ {“ status”:false,“ error”:“无效的API密钥”}“错误。虽然我使用了有效的API密钥。找不到错误。如果您能帮助我,谢谢您。
$config['rest_key_column'] = 'key';
$config['rest_key_name'] = 'X-API-KEY';
$config['rest_enable_keys'] = TRUE;
$config['rest_auth'] = basic;
控制器名称-> curlcontroller,方法-> user()
###代码在控制器文件###
public function usersresult_get()
{
return $response = $this->curl_model->user_details();
}
public function user()
{
$this->load->library('curl');
$apiKey = 'keys@345';
$apiUser = "admin";
$apiPass = "1234";
$url = 'http://192.168.1.1/ci/curlcontroller/usersresult';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-API-KEY: " . $apiKey));
curl_setopt($ch, CURLOPT_USERPWD, "$apiUser:$apiPass");
$result = curl_exec($ch);
echo $result;
curl_close($ch);
}
遇到错误->>
{"status":false,"error":"Invalid API key "}