首页 > Web开发 > 详细

curl

时间:2017-09-27 18:17:36      阅读:239      评论:0      收藏:0      [点我收藏+]

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"));

curl

原文:http://www.cnblogs.com/666-zhouliang/p/7602842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!