209 похожих чатов

Вот сделал 2 curl <?php // // A very simple PHP example that

sends a HTTP POST to a remote site
//
$ch = curl_init();
//$headers = array('Authorization: Bearer y0_AgAAAAAKTXwsAAhb7wAAAADNLLIQpCXwCVk8SmSY25K87OpW_NgHpho');

curl_setopt($ch, CURLOPT_URL, "https://api.iot.yandex.net/v1.0/user/info"); # URL to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable

curl_setopt($c, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer y0_AgAAAAAKTXwsAAhb7wAAAADNLLIQpCXwCVk8SmSY25K87OpW_NgHpho']); # custom headers, see above
$result = curl_exec( $ch ); # run!
curl_close($ch);


// Further processing ...
$result = json_decode($result, true);



$params ='{
"payload": {
"devices":
[
{
"id": "'.$result["devices"][1]["id"].'",
"custom_data": {
"api_location": "rus"
},
"capabilities": [
{
"type": "devices.capabilities.on_off",
"state": {
"instance": "on",
"value": false
}
}
]
}
]
}
}';



$headers = array('Authorization: Bearer y0_AgAAAAAKTXwsAAhb7wAAAADNLLIQpCXwCVk8SmSY25K87OpW_NgHpho',
'X-Request-Id: '.$result["request_id"],
'Content-Type: application/json' );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.iot.yandex.net/v1.0/devices/action"); # URL to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); # custom headers, see above
$result = curl_exec( $ch ); # run!
curl_close($ch);


// Further processing ...
echo "<pre>";
var_dump($result);
echo "</pre>";

и ничего не происходит

1 ответов

25 просмотров

и запрос на получение информации об УД делается методом GET, а у вас POST

Похожие вопросы

Обсуждают сегодня

Карта сайта