を試してみてくださいメッセージでキャッチされない例外「InvalidArgumentException」「ませ方法は、電子メールの設定キーを扱うことはできません」
Marcoの回答は非推奨です(jasonlfunkのコメントによる)。
長いサーバー操作のためのparams
// PUT
$client->put('http://www.example.com/user/4', [
'body' => [
'email' => '[email protected]',
'name' => 'Test user',
'password' => 'testpassword',
],
'timeout' => 5
]);
// DELETE
$client->delete('http://www.example.com/user');
非同期POSTデータ
お役立ちと
$response = $client->request('POST', 'http://www.example.com/files/post', [
'multipart' => [
[
'name' => 'file_name',
'contents' => fopen('/path/to/file', 'r')
],
[
'name' => 'csv_header',
'contents' => 'First Name, Last Name, Username',
'filename' => 'csv_header.csv'
]
]
]);
REST動詞の使用POSTファイルとは$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'http://www.example.com/user/create', [
'form_params' => [
'email' => '[email protected]',
'name' => 'Test user',
'password' => 'testpassword',
]
]);
要求。
$client = new \GuzzleHttp\Client();
$promise = $client->requestAsync('POST', 'http://www.example.com/user/create', [
'form_params' => [
'email' => '[email protected]',
'name' => 'Test user',
'password' => 'testpassword',
]
]);
$promise->then(
function (ResponseInterface $res) {
echo $res->getStatusCode() . "\n";
},
function (RequestException $e) {
echo $e->getMessage() . "\n";
echo $e->getRequest()->getMethod();
}
);
は、新しい可能性についてより詳しく説明しています。
Passing in the "body" request option as an array to send a POST request has been deprecated. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or a the "multipart" request option to send a multipart/form-data request.
不正:
$response = $client->post('http://example.com/api', [
'body' => [
'name' => 'Example name',
]
])
正しいがつがつ食うV6.0 +で
この方法は今6.0で廃止されました。 'body'の代わりに 'form_params'を使用してください。 – jasonlfunk
"body"要求オプションを配列として渡してPOST要求を送信することは推奨されていません。 application/x-www-form-urlencodedリクエストを送信するには、 "form_params"リクエストオプションを使用し、multipart/form-dataリクエストを送信するには "multipart"リクエストオプションを使用してください。 –
@JeremyQuinton、それであなたが選んだものは...返信してください – Madhur