basic_request_example.php 621 B

1234567891011121314151617181920
  1. <?php
  2. use GuzzleHttp\Client;
  3. use HttpSignatures\Context;
  4. use HttpSignatures\GuzzleHttpSignatures;
  5. require __DIR__ . "/../vendor/autoload.php";
  6. $context = new Context([
  7. 'keys' => ['examplekey' => 'secret-key-here'],
  8. 'algorithm' => 'hmac-sha256',
  9. 'headers' => ['(request-target)', 'date'],
  10. ]);
  11. $handlerStack = GuzzleHttpSignatures::defaultHandlerFromContext($context);
  12. $client = new Client(['handler' => $handlerStack]);
  13. // The below will now send a signed request to: http://example.org/path?query=123
  14. $response = $client->get("http://www.example.com/path?query=123", ['headers' => ['date' => 'today']]);