我正在使用 PHP-curl 调用 REST 调用来完成官方文档中提到的设备通知消息。下面是我的代码
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://MYHUBNAME.azure-devices.net/devices/MYDVCID/messages/deviceBound/DVCTAG?api-version=2018-06-30",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Authorization: MYSASTOKEN",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Host: MYHUBHOST",
"UserAgent: Microsoft.Azure.Devices/1.17.2",
"accept-encoding: gzip, deflate",
"cache-control: no-cache",
"content-length: "
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
在响应中,我总是收到以下 JSON 响应
{
"Message": "{"errorCode":400004,"trackingId":"XXXXXXXXX-G:7-TimeStamp:XXXXXXXX","message":"BadRequest","timestampUtc":"XXXXXXXXX"}",
"ExceptionMessage": ""
}
我尝试了很多解决它但没有得到问题,请帮助我