Last active
January 3, 2017 10:00
-
-
Save woutersf/15f3396b45981f3ab7d182b929f9624f to your computer and use it in GitHub Desktop.
Drupal8 version of drupal_http_request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$client = \Drupal::httpClient(); | |
$url = 'http://something.com/data.json'; | |
try { | |
$request = $client->get($url); | |
$status = $request->getStatusCode(); | |
//Do something here. | |
//For example: | |
return json_decode($request->getBody()->getContents()); | |
} | |
catch (RequestException $e) { | |
//An error happened. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment