第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何在 codeigniter 的 rest api 中訪問 c??url post 數(shù)據(jù)?

如何在 codeigniter 的 rest api 中訪問 c??url post 數(shù)據(jù)?

PHP
開滿天機 2023-03-11 13:56:56
我想使用 curl 將來自 Codeigniter 控制器的數(shù)據(jù)發(fā)布到 API。我無法訪問 API 中的帖子數(shù)據(jù)。這是我的 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 中的發(fā)布數(shù)據(jù)$this->input->get('skills');。
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經(jīng)驗 獲得超3個贊

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

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


查看完整回答
反對 回復 2023-03-11
  • 1 回答
  • 0 關(guān)注
  • 117 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號