php-guzzleHow to use form_params with PHP Guzzle?
Using form_params with PHP Guzzle is a simple process.
$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.
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 the form_params array which contains the data to be sent in the request.'field_name' => 'abc',
- This is an example of a key-value pair in the form_params array.'nested_field' => [
- This is an example of a nested array in the form_params array.
Helpful links
More of Php Guzzle
- How to set a user agent in PHP Guzzle?
- How to set a timeout for a request with PHP Guzzle?
- How to add an SSL certificate to a request with PHP Guzzle?
- How to handle a RequestException with PHP Guzzle?
- How to make an asynchronous send with PHP Guzzle?
- How to convert a response to an array with PHP Guzzle?
- What version of PHP is required for Guzzle?
- How to make HTTP request with PHP Guzzle?
- How to stream with PHP Guzzle?
- How to troubleshoot cURL error 60 with Guzzle in PHP?
See more codes...