亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 codeigniter 的 rest api 中訪問 c??url post 數據?

如何在 codeigniter 的 rest api 中訪問 c??url post 數據?

PHP
Smart貓小萌 2023-03-11 16:34:08
我想使用 curl 將來自 Codeigniter 控制器的數據發布到 API。我無法訪問 API 中的帖子數據。這是我的 CURL 代碼。...     class SearchJobs extends CI_Controller {public function index(){       $headers = array(        'Content-Type:application/json'    );    $fields=$this->input->post();    /////////////////////get jobs/////////////////    $api_path=API_PATH."index.php/searchJobs/getJobs";    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $api_path);    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");    curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));    $featuredJobs = curl_exec($ch);      if(curl_errno($ch)) {              echo 'Curl error: ' . curl_error($ch);            exit();        } else {              // check the HTTP status code of the request            $resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);            if ($resultStatus != 200) {                echo stripslashes($featuredJobs);                die('Request failed: HTTP status code: ' . $resultStatus);            }         $featured_jobs_array=(array)json_decode($featuredJobs);         print_r($featured_jobs_array);         exit();      }     $this->load->view('searchjobs/index',array('featuredJobs'=>$featured_jobs_array));}}...這就是我在 API 中訪問它的方式:... public function getJobs_post(){       $data_array=array();    $res_array=array();    $pageNo = $this->input->get('pageNo');    $where = ' j.isActive="y" and isApproved=1  ';    $posted_skills=$this->input->get('skills');    $locations=$this->input->get('location');...但是,我可以使用相同的方法從郵遞員輕松訪問 API 中的發布數據$this->input->get('skills');。
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

刪除 Json 標頭 $headers = array( 'Content-Type:application/json' );

并 在沒有 json_encode 的情況下直接發布數據 curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);


查看完整回答
反對 回復 2023-03-11
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號