-
-
Save richard457/e689bf6f719a07b15fbb84ea0c63128a to your computer and use it in GitHub Desktop.
Guzzle JSON example
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 | |
// GET | |
$request = $client->get($url, array('Accept' => 'application/json')); | |
$response = $request->send(); | |
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { | |
// Error | |
} | |
// POST with basic auth | |
$headers = [ | |
'Content-type' => 'application/json; charset=utf-8', | |
'Accept' => 'application/json', | |
'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), | |
]; | |
$response = $client->post($url, $headers, json_encode($data))->send(); | |
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { | |
// Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment