在PHP中处理PUT / DELETE参数 [英] Handling PUT/DELETE arguments in PHP
问题描述
我正在使用我的 CodeIgniter的REST用户端程式库,但我仍在努力了解如何在PHP中发送PUT和DELETE参数。
在一些地方,我看到人们使用以下选项:
$ this->选项(CURLOPT_PUT,TRUE);
$ this->选项(CURLOPT_POSTFIELDS,$ params);
令人讨厌的是,这似乎什么都不做。这是否是设置PUT参数的正确方法?
如果是,如何设置DELETE参数?
$ this-> option()是我的库的一部分,它只是构建一个CURLOPT_XX常量的数组,并在执行构建的cURL请求时将它们发送到curl_setopt_array()。
我试图使用下面的代码读取PUT和DELETE参数:
put':
//设置PUT变量
parse_str(file_get_contents('php:// input'),$ this-> _put_args);
break;
case'delete':
//设置PUT变量
parse_str(file_get_contents('php:// input'),$ this-> _delete_args);
break;
这里有两个选项,我接近这个错误的方式,我的图书馆。如果你能让我知道这是否理论上应该工作,我可以直接调试,直到我解决它。
我不想再浪费任何时间的方法, c>使用 CURLOPT_PUT = TRUE
code> 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屋!