在laravel中使用guzzle删除请求不起作用

问题描述 投票:0回答:1

我正在使用laravel中的资源控制器开发API。要从我的客户端调用此api,我使用guzzle(我的客户端也是laravel)。对于POST和GET请求,它工作正常,但对于删除请求,它显示以下错误。 enter image description here

我的删除请求是

$client = new Client();
$res = $client->delete('http://localhost:8017/opendemo_old/public/TestAPI/123456');

以下是我的帖子和获取请求,工作正常。

$client = new Client();
$res = $client->request('POST', 'http://localhost:8017/opendemo_old/public/TestAPI', [
        'form_params' => [
            'field_name' => 'abcddd',
            'other_field' => '12344',
            'nested_field' => [
                'nested' => 'hello'
            ]
        ]
    ]);

$client = new Client();
$res = $client->request('GET', 'http://localhost:8017/opendemo_old/public/TestAPI/123'); <br/>

我没有得到删除请求的问题。我正在使用guzzle 6和laravel 5.2(客户端和服务器)。

rest api laravel-5 guzzle guzzle6
1个回答
0
投票

DELETE请求Laravel的另一种方法。

$client = new Client();
$res = $client->post('http://localhost:8017/opendemo_old/public/TestAPI/123456', [
    'form_params' => [
        '_method' => 'DELETE'
    ]
]);
© www.soinside.com 2019 - 2024. All rights reserved.