2016-08-29 4 views
0

Ниже приведено кодирование. Но после публикации данных, я получаю сообщение об ошибке, как:Ошибка JSON при отправке данных с использованием PHP

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

После мой код:

$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); 

На самом деле я также хочу, чтобы получить данные, но детали содержатся в запросе пост данные.

ответ

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); Значение не отображается (но в кодировке я могу видеть значения) –

Смежные вопросы