簡體   English   中英

Node-Red、LoraWan 活動平台

[英]Node-Red, LoraWan Actility plattform

我正在嘗試學習如何為 Node red 中的 Actility 平台添加 http get 請求。 現在我只收到錯誤 401,即不包括授權承載。

設置是這樣完成的:

在此處輸入圖片說明

我從平台上得到兩個代碼

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer xxx' 'https://dx-api.thingpark.com/core/latest/api/devices?deviceEUI=xx&healthState=ACTIVE&statistics=true&extendedInfo=true'

首先是令牌承載。

第二個是請求網址。

https://dx-api.thingpark.com/core/latest/api/devices?deviceEUI=xxx&healthState=ACTIVE&statistics=true&extendedInfo=true

如何創建正確生成答案的流程?

謝謝。

功能設置

function節點內的 Javascript 是沙盒化的(在虛擬機中運行),因此您不能使用諸如“require”之類的某些功能。 但是,這不是問題——您可以將任何頭信息直接添加到msg.headers對象中,無論是在您的function節點中,還是在change節點中。

您沒有向我們展示您正在注入的數據,但是根據http request節點信息,您可以將所有這些(可選)字段作為輸入傳遞給 Actility 系統,這些字段可以成為請求的一部分:

 msg.url (string) If not configured in the node, this optional property sets the url of the request. msg.method (string) If not configured in the node, this optional property sets the HTTP method of the request. Must be one of GET, PUT, POST, PATCH or DELETE. msg.headers (object) Sets the HTTP headers of the request. msg.cookies (object) If set, can be used to send cookies with the request. msg.payload Sent as the body of the request.

假設您正在注入要發布到 Actility 的有效負載數據,您可以使用一個簡單的函數節點添加您需要的 Auth 標頭,該節點執行如下操作:

msg.method = "POST";
msg.headers = {
    "Authorization": "Bearer xxx",
    "Content-Type": "application/json"
};
return msg;

或者,假設您將不記名憑證字符串作為有效負載傳遞到函數中,並且您有一個固定的有效負載要發送到 Actility —— 那么您的函數可能如下所示:

msg.method = "POST";
msg.headers = {
    "Authorization": "Bearer " + msg.payload,
    "Content-Type": "application/json"
};
msg.payload = { "foo": "bar" };
return msg;

注意:為了使用這些注入的字段, http request節點之前不能將它們的值定義為節點配置的一部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM