2016-08-29 14 views
0

以下は、私が行ったコーディングです。PHPを使用したデータ投稿時のJSONエラー

$auth_token=$_REQUEST['auth_token']; 
$ch = curl_init('https://api.datonis.io/api/v3/datonis_query/thing_aggregated_data'); 
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE, 
CURLOPT_RETURNTRANSFER => TRUE, 

CURLOPT_HTTPHEADER => array(
     'X-Auth-Token:'.$auth_token, 
     'thing_key:6f2159f998', 
     'idle_time_required:true', 
     'from:2016/02/02 17:05:00', 
     'to:2016/08/29 17:10:00', 
     'time_zone:Asia/Calcutta', 
     'Content-Type:application/json', 
), 


)); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

// Send the request 
$response = curl_exec($ch); 

// Check for errors 
if($response === FALSE){ 
    die(curl_error($ch)); 
} 

// Decode the response 
//var_dump($response); 
$responseData = json_decode($response, TRUE); 

// Print the date from the response 
var_dump($responseData); 

実は私もデータを取得したいが、詳細はPOSTリクエストに含まれています。私のコードが続き

'message' => string ''from' and 'to' date must be given' (length=34).

:しかし、データを投稿した後、私はエラーを取得していますデータ。

答えて

0

使用 "CURLOPT_POSTFIELDS":

$data = array("from" => "2016/02/02 17:05:00", "to" => "2016/08/29 17:10:00");                  
$data_string = json_encode($data);                     

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                  
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                   
    'Content-Type: application/json')                  
+0

今すぐjson_decode($応答、TRUE)を復号化する際に問題に直面しています。 値は表示されません(しかし、値を見ることができるエンコーディングでは) –

関連する問題