【问题标题】:Why $_POST is empty in codeigniter?为什么 $_POST 在 codeigniter 中是空的?
【发布时间】:2019-12-27 15:35:14
【问题描述】:

我用 Codeigniter 创建了一个简单的 Rest web 服务。 当我从另一个应用程序使用 Curl 发送发布数据并显示 $_POST 为空时。

简单的 PHP 客户端:

$url = 'http://localhost/ci-access/api_v1/register_events';
$data = array(
    'name' => 'tester'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$output  = curl_exec($ch);
curl_close($ch);

Codeigniter 网络服务:

public function register_events() {
    die(var_dump($_POST));
}

是否有在 Codeigniter 中设置的选项? 如何读取发布的数据?

【问题讨论】:

    标签: php codeigniter web-services php-curl


    【解决方案1】:

    尝试先传递php curl_setopt($ch, CURLOPT_POST, true); 选项或将其删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-21
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多