Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS-Guzzle我们计算的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法_Amazon Web Services_Aws Api Gateway_Guzzle_Guzzlehttp_Psr 7 - Fatal编程技术网

Amazon web services AWS-Guzzle我们计算的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法

Amazon web services AWS-Guzzle我们计算的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法,amazon-web-services,aws-api-gateway,guzzle,guzzlehttp,psr-7,Amazon Web Services,Aws Api Gateway,Guzzle,Guzzlehttp,Psr 7,我正在使用SignatureV4 aws身份验证来验证我的API调用, 我还使用Guzzle/Client来调用API 通过遵循上述步骤,我的API调用仅适用于GET方法,而不适用于POST方法。对于POST方法调用,它显示错误(我们计算的请求签名与您提供的签名不匹配。请检查您的AWS秘密访问密钥和签名方法) 我的代码: use Aws\Credentials\CredentialProvider; use Aws\Signature\SignatureV4; use GuzzleHttp\Cl

我正在使用SignatureV4 aws身份验证来验证我的API调用, 我还使用Guzzle/Client来调用API

通过遵循上述步骤,我的API调用仅适用于GET方法,而不适用于POST方法。对于POST方法调用,它显示错误(我们计算的请求签名与您提供的签名不匹配。请检查您的AWS秘密访问密钥和签名方法)

我的代码:

use Aws\Credentials\CredentialProvider;
use Aws\Signature\SignatureV4;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$request = new Request(
    'POST',
    'https://XXXXXXXXXXXXx.com/XXXXXx/XXXXXXx',
    [
        'body' => '{
            "param1": "loream",
            "param2": "4970",
            "param3": "1",
            "param4": "2.0",
            "param5": "mL",
            "param6": "kgs",
            "param7": 0,
        }'
    ]      
);

$key['credentials'] = array( 
    'key'    => 'XXXXXXXXXXXXXXX-access-key',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-secret-key'
);

$credentials = call_user_func(CredentialProvider::defaultProvider(
    $key
));

// Construct a request signer
$signer = new SignatureV4('execute-api', 
                        'us-east-1'
);

// Sign the request
$request = $signer->signRequest($request, $credentials);

// Send the request
try {
    $response = (new Client)->send($request);
    print_r($response);
}
    catch (Exception $exception) {
    $responseBody = $exception->getResponse()->getBody(true);
    echo $responseBody;
}
$response = (new Client)->send($request);

$results = json_decode($response->getBody());

此问题已解决,Request()中存在语法错误,这应遵循传递的参数的顺序。我得到此错误:致命错误:未捕获类型错误:传递给Aws\Signature\SignatureV4::signRequest()的参数2必须是Aws\Credentials\CredentialsInterface的实例,GuzzleHttp\Promise\Promise的实例