如何使用API​​密钥发出curl请求?

时间:2019-09-19 10:45:55

标签: php curl request api-key

我从收到的文档中获得了端点和apiKey,但是在传递令牌时,我仍然遇到相同的错误:

  

“ {” message“:”授权标头需要'Credential'参数。授权标头需要“签名”参数。授权标头需要“ SignedHeaders”参数。授权标头要求存在“ X-Amz-Date”或“ Date”标头。 Authorization = Basic 123456789717896 =“}”

我的代码:

    $endpoint = 'https://my.example.co.uk/full-example-new/prod';
    $apiKey = '123456789717896';

    $ch = curl_init();

    $headers = array();
    $headers[] = 'Authorization: Basic';
    $headers[] = 'x-api-key: ' . $apiKey;
    $headers[] = 'Credential:' . '';
    $headers[] = 'Signature:' . '';
    $headers[] = 'SignedHeaders:' . '';
    $headers[] = 'X-Amz-Date' . date( 'Ymd\THis\Z');

    curl_setopt($ch, CURLOPT_URL, $endpoint);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    $body = '{}';
    curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $something = curl_exec($ch);

    return $something;

在文档中:

  

您需要将以下标头添加到auth:

x-api-key: 123456789717896 

我该如何解决?

0 个答案:

没有答案