使用 REST API 的 Azure 调用设备模块方法

Azure Invoke Device Module method using REST API

我想使用 Azure 中的调用设备模块 API,我想在其中使用 API 发送有效载荷,它将负责从云向模块发送消息。我正在关注这篇文章“https://docs.microsoft.com/en-us/rest/api/iothub/digitaltwinmodel/service/invokedevicemodulemethod

我正在使用 postman 来执行此 API,但我收到以下响应。

我在邮递员1]中添加了2个headers授权,在此我添加了一个bearerToken和2]content-type作为application/json。我在 body 部分给出了一个有效负载。请让我知道这里可能出了什么问题,或者我是否需要以其他方式配置它。

URLhttp://azure-devices.net//twins. Can you please try with correct http://azure-devices.net/twins/

中有一个双斜杠

我知道它是怎么做的了。 我们需要做的就是在授权中使用 SAS Token header 而不是 bearerToken 并使用下面的 body.

{
"methodName": "name_of_your_method",
"responseTimeoutInSeconds": 60,
 "payload": {
    "command": "your_message"}
}

APIURL就是下面的POST方法

"https://fully-qualified-iothubname.azure-devices.net/twins/{deviceId}/modules/{moduleId}/methods?api-version=2019-07-01-preview"

使用以下命令生成 SAS 令牌,FYI SAS 令牌在生成 1 小时后过期:

az iot hub generate-sas-token -n Ageye

这工作得很好并给出了以下响应:

{
    "status": 200,
    "payload": {
        "status": "ok"
    }
}