php-guzzleHow to use form data with PHP Guzzle?
Using PHP Guzzle to work with form data is quite simple.
$client = new GuzzleHttp\Client();
$response = $client->request('POST', 'http://httpbin.org/post', [
'form_params' => [
'field_name' => 'abc',
'other_field' => '123',
'nested_field' => [
'nested' => 'hello'
]
]
]);
The output of the above code will be a response object containing the response from the server.
Code explanation
$client = new GuzzleHttp\Client();
- This creates a new Guzzle client object.$response = $client->request('POST', 'http://httpbin.org/post', [
- This sends a POST request to the specified URL.'form_params' => [
- This is an array containing the form data to be sent.'field_name' => 'abc',
- This is an example of a field name and value pair.'nested_field' => [
- This is an example of a nested field.
Helpful links
More of Php Guzzle
- How to send multipart requests with Guzzle in PHP?
- How to set a user agent in PHP Guzzle?
- How to use PHP Guzzle to make a batch request?
- How to use Promises with PHP Guzzle (with an example)?
- How to make an asynchronous send with PHP Guzzle?
- How to set a timeout for a request with PHP Guzzle?
- How to set Guzzle options in PHP?
- How to make an HTTP POST request with JSON using PHP Guzzle?
- How to post form data with PHP Guzzle?
- How to send multiple requests with Guzzle in PHP?
See more codes...