在 PHP 中处理 PUT/DELETE 参数 [英] Handling PUT/DELETE arguments in PHP
问题描述
我正在开发我的 用于 CodeIgniter 的 REST 客户端库,我正在努力弄清楚如何在 PHP 中发送 PUT 和 DELETE 参数.
在一些地方,我看到有人使用这些选项:
$this->option(CURLOPT_PUT, TRUE);$this->option(CURLOPT_POSTFIELDS, $params);
恼人的是,这似乎没有任何作用.这是设置PUT参数的正确方法吗?
如果是这样,我该如何设置 DELETE 参数?
$this->option() 是我的库的一部分,它只是构建一个 CURLOPT_XX 常量数组,并在构建的 cURL 请求执行时将它们发送到 curl_setopt_array(). >
我正在尝试使用以下代码读取 PUT 和 DELETE 参数:
case 'put'://设置PUT变量parse_str(file_get_contents('php://input'), $this->_put_args);休息;案例删除"://设置PUT变量parse_str(file_get_contents('php://input'), $this->_delete_args);休息;
这里有两个选项,我以错误的方式处理这个问题,或者我的库中某处存在错误.如果你能让我知道这在理论上是否可行,我可以在调试之前进行调试,直到我解决它.
我不想再浪费时间在一个根本错误的方法上.
不要使用 CURLOPT_PUT = TRUE
使用 CURLOPT_CUSTOMREQUEST = 'PUT'
和 CURLOPT_CUSTOMREQUEST = 'DELETE'
然后只需使用 CURLOPT_POSTFIELDS
设置值.
I am working on my REST client library for CodeIgniter and I am struggling to work out how to send PUT and DELETE arguments in PHP.
In a few places I have seen people using the options:
$this->option(CURLOPT_PUT, TRUE);
$this->option(CURLOPT_POSTFIELDS, $params);
Annoyingly, this seems to do nothing. Is this the correct way to set PUT parameters?
If so, how do I set DELETE parameters?
$this->option() is part of my library, it simply builds up an array of CURLOPT_XX constants and sends them to curl_setopt_array() when the built up cURL request is executed.
I am attempting to read PUT and DELETE parameters using the following code:
case 'put':
// Set up out PUT variables
parse_str(file_get_contents('php://input'), $this->_put_args);
break;
case 'delete':
// Set up out PUT variables
parse_str(file_get_contents('php://input'), $this->_delete_args);
break;
There are two options here, I am approaching this in the wrong way or there is a bug somewhere in my libraries. If you could let me know if this should theoretically work I can just hammer away on debug until I solve it.
I dont want to waste any more time on an approach that is fundamentally wrong.
Instead of using CURLOPT_PUT = TRUE
use CURLOPT_CUSTOMREQUEST = 'PUT'
and CURLOPT_CUSTOMREQUEST = 'DELETE'
then just set values with CURLOPT_POSTFIELDS
.
这篇关于在 PHP 中处理 PUT/DELETE 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!