如何在Guzzle 5中发送PUT请求的参数? [英] How do I send parameters for a PUT request in Guzzle 5?
本文介绍了如何在Guzzle 5中发送PUT请求的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有用于发送POST请求参数的代码,该代码有效:
I have this code for sending parameters for a POST request, which works:
$client = new GuzzleHttp\Client();
$request = $client->createRequest('POST', 'http://example.com/test.php');
$body = $request->getBody();
$request->getBody()->replaceFields([
'name' => 'Bob'
]);
但是,当我将POST更改为PUT时,会出现此错误:
However, when I change POST to PUT, I get this error:
Call to a member function replaceFields() on a non-object
这是因为getBody返回null.
This is because getBody is returning null.
在体内发送PUT参数实际上正确吗?还是应该在URL中完成?
Is it actually correct to send PUT parameters in the body? Or should I do it in the URL?
推荐答案
查看全文