Created
February 22, 2016 11:35
-
-
Save roberto-butti/d13f4841f012f247bbbc to your computer and use it in GitHub Desktop.
Send a JSON in a POST, with HTTP Basic Auth (Guzzle Version)
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 | |
$endpoint_url="your_url_here"; | |
$string_json = "your_json_string"; | |
$username="username"; | |
$password ="password"; | |
$client = new Client(); | |
$options= array( | |
'auth' => [ | |
$username, | |
$password | |
], | |
'headers' => ['content-type' => 'application/json', 'Accept' => 'application/json'], | |
'body' => $string_json, | |
"debug" => true | |
); | |
try { | |
$res = $client->post($endpoint_url, $options); | |
} catch (ClientException $e) { | |
echo $e->getRequest() . "\n"; | |
if ($e->hasResponse()) { | |
echo $e->getResponse() . "\n"; | |
} | |
} | |
echo "OO<h1>".$res->getStatusCode()."</h1>OO"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias