CURL傳遞多維數組

<?php
header("Content-type: text/html;charset=utf-8");
$url = "";
// 參數數組
$data = array (
'name' => 'tanteng',
'password' => 'password',
'method' => array(1,2,3)
);
$ch = curl_init ();
// print_r($ch);
$data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// 我們在POST數據哦!
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的變量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
       /*   curl_setopt($ch, CURLOPT_HTTPHEADER, array(   如果添加了頭部說明,dump($GLOBALS['HTTP_RAW_POST_DATA']);可以接受到
              'Content-Type: application/json',                            如果沒有添加頭部說明   dump( file_get_contents("php://input")); 可以接受到
              'Content-Length: ' . strlen($data)
          ));*/
$output = curl_exec($ch);
var_dump($output);
curl_close($ch);





接受時

dump($_POST);   

dump($GLOBALS['HTTP_RAW_POST_DATA']);

dump( file_get_contents("php://input"));
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章