2017-05-03 8 views
0

私はcurlを使用してDreamFactoryのURLからJSONデータを取得しています。 しかし、私はエラーを取得します。リクエストにセッショントークン(JWT)またはAPIキーが見つかりませんPHPでエラーが発生しました

リクエストでセッショントークン(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 protected]&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); 
?> 

アドバイスをしてください!

答えて

1

このように使用します。

<?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 protected]&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); 
?> 
:あなたの終わりに、ヘッダーを開始する必要はありません、あなたはあなたのコードで

$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コードをこれらの数行を追加することによって、あなたのAPI-Key

が含まれているヘッダを送信する必要が

+0

"error":{"code":403、 "context":null、 "message": "オープン登録が有効になっていません。 –

+0

@RamaLingam上記のエラーが修正されました。このためには、dev.spotya.onlineのapidocsを調べる必要があります。 –

+0

うまくいきます。変更後、 'Open Registrationが有効になります.' –

関連する問題