[英]how to send array in rest api php
我想在php中發送帶有rest api的數組,但我不知道該怎么做
我嘗試使用 json 而沒有 json 但沒有回應我
$drv = array('mobile'=>'+123456', 'title'=>"MR", 'firstName_en'=>'john', 'lastName_en'=>'wilet');
curl_setopt($process, CURLOPT_POSTFIELDS, "checkoutStation=xxx&checkoutDate=20190826&checkoutTime=0900&checkinStation=xxx&checkinDate=20190827&checkinTime=0900&email=info@site.net&driver=$drv");
也試試
$drv = array('mobile'=>'+123456', 'title'=>"MR", 'firstName_en'=>'john', 'lastName_en'=>'wilet');
$drv=json_encode($drv);
curl_setopt($process, CURLOPT_POSTFIELDS, "checkoutStation=xxx&checkoutDate=20190826&checkoutTime=0900&checkinStation=xxx&checkinDate=20190827&checkinTime=0900&email=info@site.net&driver=$drv");
因為驅動程序參數在我運行代碼時需要一個數組數據值返回錯誤":["驅動程序數據中的錯誤!"] 給我
您需要使用參數數組構建查詢字符串
$params = array(
'checkoutStation' => 'xxx',
'checkoutDate' => '20190826',
'checkoutTime' => '0900',
'checkinStation' => 'xxx',
'checkinDate' => '20190827',
'checkinTime' => '0900',
'email' => 'info@site.net',
'driver' => array(
'mobile'=>'+123456',
'title'=>"MR",
'firstName_en'=>'john',
'lastName_en'=>'wilet'
)
);
curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($params));
$data=array('mobile'=>'+123456','title'=>"MR",'firstName'=>'john','lastName'=>'wilet'); $drv=json_encode($data); curl_setopt($process, CURLOPT_POSTFIELDS, "&driver=$drv");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.