使用Guzzle进行摘要式身份验证

时间:2016-12-29 23:18:20

标签: php json authentication guzzle digest

尝试从使用摘要式身份验证的API获取JSON响应。我正在为客户使用Guzzle。

这是我到目前为止所做的并且似乎无法奏效。有什么建议吗?

<?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']]);

2 个答案:

答案 0 :(得分:1)

<?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),
        ]);

答案 1 :(得分:0)

检查是否安装了php-curl扩展名。如果没有安装。对于Linux:

sudo apt-get install php-curl