How do I send parameters for a PUT request in Guzzle 5?

扶醉桌前 提交于 2019-12-03 13:44:32

According to the manual,

The body option is used to control the body of an entity enclosing request (e.g., PUT, POST, PATCH).

The documented method of put'ing is:

$client = new GuzzleHttp\Client();

$client->put('http://httpbin.org', [
    'headers'         => ['X-Foo' => 'Bar'],
    'body'            => [
        'field' => 'abc',
        'other_field' => '123'
    ],
    'allow_redirects' => false,
    'timeout'         => 5
]);

Edit

Based on your comment:

You are missing the third parameter of the createRequest function - an array of key/value pairs making up the post or put data:

$request = $client->createRequest('PUT', '/put', ['body' => ['foo' => 'bar']]);
Ali Özyıldırım

when service ise waiting json raw data

$request = $client->createRequest('PUT', '/yourpath', ['json' => ['key' => 'value']]);

or

$request = $client->createRequest('PUT', '/yourpath', ['body' => ['value']]);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!