curl

curl想要傳遞二維數組.或者更維的數組時php

<?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);html

 

 

接受時json

dump($_POST);   數組

dump($GLOBALS['HTTP_RAW_POST_DATA']);app

dump( file_get_contents("php://input"));curl

相關文章
相關標籤/搜索