我無法讓 API 休息來檢查許可證的運行狀況。
api.php(在控制器下)
<?php
require APPPATH . '/libraries/REST_Controller.php';
use Restserver\Libraries\REST_Controller;
class Inmobiapi extends REST_Controller {
/**
* Get All Data from this method.
*
* @return Response
*/
public function __construct() {
parent::__construct();
$this->load->database();
}
/**
* Get All Data from this method.
*
* @return Response
*/
public function index_post()
{
$licencia=$this->input->post('licencia');
if($licencia){
$data = $this->db->get_where("clientes", ['licencia' => $licencia,'status'=>'Active'])->row_array();
}else{
$this->response(NULL, 404);
}
$this->response($data, REST_Controller::HTTP_OK);
}
}
檢查許可證的功能,它是一個助手。
function verificar_licencia($licencia){
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'URL_TO_API');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $licencia);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
$result = json_decode($buffer);
if(isset($result))
{
return $result;
}
else
{
return FALSE;
}
}
回報總是給我 FALSE。api 檔案托管在具有不同 CI3 安裝但在兩個 rest.php 上的配置相同的其他域上
未啟用身份驗證,因此任何人都可以訪問(我只是在測驗)。
有人可以指導我嗎?謝謝。
uj5u.com熱心網友回復:
我假設您有一個有效的“URL_TO_API”值。檢查您的 CURL 選項。如果您沒有從呼叫中獲得結果并且您的 URL 有效且正常,則您的curl_setopt呼叫可能缺少或設定了(或未設定)不正確的屬性。
例如,在我最新的專案中,我的 curl 選項必須設定如下:
curl_setopt_array($curl, [
CURLOPT_URL => 'https://path/to/endpoint'
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_VERBOSE => 1,
CURLOPT_NOBODY => 1,
CURLOPT_MAXREDIRS => 1,
CURLOPT_POST => 1,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => []
]);
對您來說可能會有所不同,具體取決于:
- 您想通過通話實作的目標。
- 端點需要您設定的內容 - 請參閱您的端點檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/456854.html
