我有一个thingsuno板。如果我在 CLI 中执行此命令,我想通过 POST 请求(http 集成)打开板上的一个 LED,它可以工作:
curl -i -X POST --data '{"dev_id":"myid","port": 1,"confirmed": false, "payload_raw": "MDA="}' https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/myapplication/test?key=ttn-account-v2.thekey
但现在我想用 PHP 来做,所以我有这个代码:
<?php
//API Url
$endpoint_url = 'https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/myapp/test?key=ttn-account-v2.mykey';
$data_to_post = [
'dev_id' => 'mydevice',
'port' => 1,
'confirmed' => false,
'payload_raw' => 'MDA='];
$options = [
CURLOPT_URL => $endpoint_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data_to_post,`enter code here`
CURLOPT_SSL_VERIFYPEER=> false
];
$curl = curl_init();
curl_setopt_array($curl, $options);
curl_exec($curl);
var_dump(curl_getinfo($curl));
curl_close($curl);
它只返回 HTTP400 badrequest。我究竟做错了什么 ?