php-symfonyHow to make an HTTP request in PHP Symfony?
Making an HTTP request in PHP Symfony is easy and straightforward.
Example code
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'http://example.com');
Output example
GuzzleHttp\Psr7\Response {#741
-reasonPhrase: 'OK'
-statusCode: 200
-headers: array:7 [ …7]
-headerLines: array:7 [ …7]
-protocol: '1.1'
-stream: GuzzleHttp\Psr7\Stream {#742 …}
}
Code explanation
$client = new \GuzzleHttp\Client();
- creates a new Guzzle client instance$response = $client->request('GET', 'http://example.com');
- sends a GET request to the specified URL and stores the response in the$response
variable
Helpful links
More of Php Symfony
- How to create a model in PHP Symfony?
- How to install Symfony on Windows?
- How to do testing with PHP Symfony?
- How to upload a file in PHP Symfony?
- How to create a migration in PHP Symfony?
- How to create a backend with PHP Symfony?
- How to get request parameters in PHP Symfony?
- How to use the PHP Symfony Finder?
- How to use websockets in PHP Symfony?
- How to check PHP Symfony version?
See more codes...