Php 使用Guzzle删除带有参数的请求
我必须在CodeIgnitor平台上使用参数执行删除请求。首先,我试着用卷发,但我换成了狂饮 控制台中的请求示例如下:Php 使用Guzzle删除带有参数的请求,php,codeigniter,curl,guzzle,http-delete,Php,Codeigniter,Curl,Guzzle,Http Delete,我必须在CodeIgnitor平台上使用参数执行删除请求。首先,我试着用卷发,但我换成了狂饮 控制台中的请求示例如下: curl-X DELETE-d'{“用户名”:“测试”}http://example.net/resource/id 但是在Guzzle的文档中,他们使用的参数就像GET,比如DELETEhttp://example.net/resource/id?username=test,我不想这样做 我试过: $client = new GuzzleHttp\Client(); $cl
curl-X DELETE-d'{“用户名”:“测试”}http://example.net/resource/id
但是在Guzzle的文档中,他们使用的参数就像GET,比如DELETEhttp://example.net/resource/id?username=test
,我不想这样做
我试过:
$client = new GuzzleHttp\Client();
$client->request('DELETE', $url, $data);
但是请求只是调用
DELETEhttp://example.com/resource/id
不带任何参数。如果我正确解释了您的curl请求,您将尝试发送json数据作为删除请求的主体
// turn on debugging mode. This will force guzzle to dump the request and response.
$client = new GuzzleHttp\Client(['debug' => true,]);
// this option will also set the 'Content-Type' header.
$response = $client->delete($uri, [
'json' => $data,
]);
在吃了同样的东西之后,在这个问题上迟到了。 首选解决方案,避免调试模式是在“查询”中传递参数,如下所示:
$response = $client->request('DELETE', $uri, ['query' => $datas]);
$datas是一个数组
狂饮V6
这也将给出响应的状态为204或404谢谢。解决了我的问题
$response = json_decode($this->client->delete($uri,$params)->getStatusCode());
echo $response;