Php 用Guzzle进行摘要认证
试图从使用摘要身份验证的API获取JSON响应。我正在为客户使用Guzzle 这是我到目前为止所做的,似乎不起作用。有什么建议吗Php 用Guzzle进行摘要认证,php,json,authentication,guzzle,digest,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('ver
<?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']]);
检查是否安装了php curl扩展。如果没有安装它。对于linux:
sudo-apt-get-install-php-curl
您使用的是哪个版本的guzzle?我使用的是6版,您是否测试通过了请求方法中的“验证”选项?例如“$client->request('POST','/json',['verify'=>false,'auth'=>['username',password',digest'])”;“请不要添加多个问题。回答最好的一个,并将其余的标记为重复项。看见
<?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),
]);