0

我正在使用curlfor从url获取JSON数据。DreamFactory但我得到了错误。

请求中未检测到会话令牌 (JWT) 或 API 密钥。请发送 X-DreamFactory-Session-Token 和/或 X-Dreamfactory-API-Key 请求标头。您还可以使用 URL 查询参数 session_token 和/或 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);
?>

请指教!

4

1 回答 1

2

像这样使用它。无需在您的最后启动标头,您必须发送包含您的标头API-Key

通过在代码中添加这几行

$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);
?>
于 2017-05-03T06:28:12.343 回答