无法将负载参数传递给 Node-RED http 请求
Unable to pass payload parameters to Node-RED http request
我正在尝试在 Node-RED 中执行一个简单的 http get 请求。根据在线文档,我必须在函数中传递参数作为 http 请求节点的输入。我的函数看起来像这样;
msg.url = "https://api.socialstudio.radian6.com/v3/posts"
msg.method = "GET"
msg.headers = {'access_token': access_token}
msg.payload = {
'topics': 234243,
'limit': 100,
}
return msg;
然而,当我查看服务器响应时,出现错误:
["{"error":{"message":"Missing topics parameter.","statusCode":400,"errorCode":"MC-Unknown","requestId":"RnY9E0pbcU1lkiaf"},"meta":null}"][1]
我试过其他 api 的,但我还不能传递有效负载参数。
我做错了什么?
msg.payload
包含请求的主体,但您尝试查询的服务器似乎需要将数据作为查询字符串传递。
试试这个:
msg.url = "https://api.socialstudio.radian6.com/v3/posts?topics=234243&limit=100"
(并删除 msg.payload
)
如果您想为 GET 请求传递查询参数,您应该在 http request node
中设置基础 URL 并使用 mustache 语法来包含它们:
https://api.socialstudio.radian6.com/v3/posts?topics={topics},limit={limts}
并将功能节点更改为:
msg.method = "GET"
msg.headers = {'access_token': access_token}
msg.topics = 234243;
msg.limit = 100;
return msg;
如果有人偶然发现这个问题,现在可以告诉 Node-Red 自动将有效负载编码为 GET 请求的查询字符串参数。
首先,在payload
中设置function
中的参数:
msg.headers = {'access_token': access_token}
msg.payload = {
'topics': 234243,
'limit': 100,
}
return msg;
然后,添加一个 http request
节点并配置如下:
我正在尝试在 Node-RED 中执行一个简单的 http get 请求。根据在线文档,我必须在函数中传递参数作为 http 请求节点的输入。我的函数看起来像这样;
msg.url = "https://api.socialstudio.radian6.com/v3/posts"
msg.method = "GET"
msg.headers = {'access_token': access_token}
msg.payload = {
'topics': 234243,
'limit': 100,
}
return msg;
然而,当我查看服务器响应时,出现错误:
["{"error":{"message":"Missing topics parameter.","statusCode":400,"errorCode":"MC-Unknown","requestId":"RnY9E0pbcU1lkiaf"},"meta":null}"][1]
我试过其他 api 的,但我还不能传递有效负载参数。
我做错了什么?
msg.payload
包含请求的主体,但您尝试查询的服务器似乎需要将数据作为查询字符串传递。
试试这个:
msg.url = "https://api.socialstudio.radian6.com/v3/posts?topics=234243&limit=100"
(并删除 msg.payload
)
如果您想为 GET 请求传递查询参数,您应该在 http request node
中设置基础 URL 并使用 mustache 语法来包含它们:
https://api.socialstudio.radian6.com/v3/posts?topics={topics},limit={limts}
并将功能节点更改为:
msg.method = "GET"
msg.headers = {'access_token': access_token}
msg.topics = 234243;
msg.limit = 100;
return msg;
如果有人偶然发现这个问题,现在可以告诉 Node-Red 自动将有效负载编码为 GET 请求的查询字符串参数。
首先,在payload
中设置function
中的参数:
msg.headers = {'access_token': access_token}
msg.payload = {
'topics': 234243,
'limit': 100,
}
return msg;
然后,添加一个 http request
节点并配置如下: