Skip to content

Instantly share code, notes, and snippets.

@roberto-butti
Created February 22, 2016 11:35
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save roberto-butti/d13f4841f012f247bbbc to your computer and use it in GitHub Desktop.
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)
<?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";
@shadowsberg
Copy link

Gracias

@lfnna1977
Copy link

igualmente gracias, me salvaste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment