如何在PHP中获取PUT / DELETE参数
发布时间:2020-12-13 17:46:13 所属栏目:PHP教程 来源:网络整理
导读:我正在编写REST Web服务,并想知道如何处理put或delete参数是 PHP. 我正在接受如下输入, $input = file_get_contents('php://input');echo $input; output = imei = 1234567890 email=hello@gmail1.com 我怎样才能访问这些变量 echo $_POST['imei'];echo $_PO
我正在编写REST Web服务,并想知道如何处理put或delete参数是
PHP.
我正在接受如下输入, $input = file_get_contents('php://input'); echo $input; output = imei = 1234567890& email=hello@gmail1.com 我怎样才能访问这些变量 echo $_POST['imei']; echo $_POST['email']; echo $_GET['imei']; echo $_GET['email']; 我发现在PHP中没有像$_PUT或$_DELETE来处理输入参数.得到这个的方法是什么? 解决方法
你能试试这个吗,PHP没有内置的方法来做这个,可以从传入的流中读取到PHP,php:// input.
parse_str(file_get_contents("php://input")); EX: if($_SERVER['REQUEST_METHOD'] == 'GET') { echo "this is a get requestn"; echo $_GET['fruit']." is the fruitn"; echo "I want ".$_GET['quantity']." of themnn"; } elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { echo "this is a put requestn"; parse_str(file_get_contents("php://input"),$post_vars); echo $post_vars['fruit']." is the fruitn"; echo "I want ".$post_vars['quantity']." of themnn"; } 参考:http://www.lornajane.net/posts/2008/accessing-incoming-put-data-from-php (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |