zoukankan      html  css  js  c++  java
  • curl

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

  • 相关阅读:
    Java进阶知识查漏补缺06
    SQL学习记录(concat)
    Restful API学习
    git学习
    获得xmlhttp对象
    vue-cli初接触
    vue初接触
    java使用百度UNIT
    JSON学习
    通用Mapper警告:建议修改基本类型为对应的包装类型!
  • 原文地址:https://www.cnblogs.com/666-zhouliang/p/7602842.html
Copyright © 2011-2022 走看看