PHP 请求错误中未检测到会话令牌 (JWT) 或 API 密钥

No session token (JWT) or API Key detected in request Error in PHP

我正在使用 curlDreamFactory url 获取 JSON 数据。 但是我收到了错误。

No session token (JWT) or API Key detected in request. Please send in X-DreamFactory-Session-Token and/or X-Dreamfactory-API-Key request header. You can also use URL query parameters session_token and/or api_key.

我的php代码

<?php
header("X-DreamFactory-API-Key:TestKey"); 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://dev.spotya.online:82/api/v2/user/register/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"email=ramalingam.p@pickzy.com&first_name=Ramalingam&last_name=Perumal&display_name=Ramalingam&new_password=123456&phone=1234567890");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);

print_r($server_output);
?>

请指教!

这样使用。您无需启动 headers,您必须发送包含您的 API-Key

的 header

通过在您的代码中添加这几行

$headers=array(
            "X-DreamFactory-API-Key: TestKey" //your api-key
        );
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);// adding headers with curl-request

完成PHP代码:

<?php
$headers=array(
            "X-DreamFactory-API-Key: TestKey" 
        ); 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://dev.spotya.online:82/api/v2/user/register/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"email=ramalingam.p@pickzy.com&first_name=Ramalingam&last_name=Perumal&display_name=Ramalingam&new_password=123456&phone=1234567890");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);

print_r($server_output);
?>