【问题标题】:Guzzle 6 PUT request shows deprecated methodGuzzle 6 PUT 请求显示不推荐使用的方法
【发布时间】:2016-10-18 15:47:54
【问题描述】:

我正在使用 guzzle http 6 向我的服务器发送一个 put 请求。在他们的文档中,它说发送带有数据的 put 请求的方式就像

$client->request('PUT', $url, ['body' => 'foo']);

但是当我尝试时,我得到了这个错误

顺便提一下,我在 laravel 5.3 上使用 guzzle http

【问题讨论】:

    标签: http request guzzle laravel-5.3


    【解决方案1】:

    您的第三个参数应该是标题。第四个应该是body。

    下面是http://docs.guzzlephp.org/en/latest/psr7.html?highlight=put的示例

    $headers = ['X-Foo' => 'Bar'];
    $body = 'hello!';
    $request = new Request('PUT', 'http://httpbin.org/put', $headers, $body);
    

    在你的情况下,应该是:

    $client->request('PUT', $url, [], ['body' => 'foo']);
    

    【讨论】:

    • 它清除了以前的错误,但现在我面临另一个问题。我的请求现在遇到了异常。这是我的代码-
    • try{ $response = $client->request($method, $url, [], [ 'body' =>$data ]); $result = json_decode($response->getBody(), true);返回$结果; } catch (RequestException $e) { echo Psr7\str($e->getRequest()); if ($e->hasResponse()) { return '不成功'; } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 2020-10-08
    • 2015-06-26
    相关资源
    最近更新 更多