3

Trying to get to get JSON response from API that uses digest authentication. I am using Guzzle for the client.

This is what I have so far and doesn't seem to work. Any suggestion?

<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client([
'base_uri' => 'https://10.1.1.1',
'timeout'  => 2.0,
]);

$client->setDefaultOption('verify', false);
$client->request('POST', '/json', ['auth' => ['username', 'password', 'digest']]);
Sujan
  • 150
  • 10

2 Answers2

3
<?php

require 'vendor/autoload.php';
use GuzzleHttp\Client;

$client = new Client();

$query = '{"id":1}'; //json payload if any

$result = $client->request(
        'POST',
        'https://10.1.1.1/json', [
            'verify' => false,
            'auth' => ['username', 'password', 'digest'],
            'json' => json_decode($query, true),
        ]);
Sujan
  • 150
  • 10
0

Check if php-curl extension is installed. If not install it. For linux:

sudo apt-get install php-curl

Tom
  • 2,242
  • 18
  • 27
  • Please don't add [the same answer](http://stackoverflow.com/a/51622772) to multiple questions. Answer the best one and flag the rest as duplicates. See [Is it acceptable to add a duplicate answer to several questions?](http://meta.stackexchange.com/q/104227/347985) – Paul Roub Jul 31 '18 at 22:12