请问http节点的url里怎么传参数
我爬取了我汽车的gps,但是直接展现在ha上有偏移,想用node-red调用百度的api做坐标纠偏,但是url上不会带动态参数,求稳如何解:我现在的函数节点为
msg.coords = http节点的url为
https://api.map.baidu.com/geoconv/v1/?coords={coords}&from=3&to=5&ak=xxxAPI要求的格式是
https://api.map.baidu.com/geoconv/v1/?coords=114.21892734521,29.575429778924&from=1&to=5&ak=你的密钥 //GET请求
但是运行就报错
{"status":24,"message":"param error:coords format error"}"
这样:
在 http request 节点中 url 中 只填 https://api.map.baidu.com/geoconv/v1/,内容 选择Append to query-string parameters
在前面放一个 function 节点,设置 msg.payload= {'coords':'coords的值', 'from':3}
本帖最后由 dscao 于 2023-2-7 21:05 编辑
msg.coords =
let coords = msg.coords
msg.url = `https://api.map.baidu.com/geoconv/v1/?coords=${coords},${coords}&from=3&to=5&ak=xxx`
这样应该也可以吧
用 json 格式的 payload
类似这样的
[
{
"id": "803e95821262ec23",
"type": "function",
"z": "5bfc1ec08cb3472e",
"name": "钉钉消息预处理",
"func": "var message='湿度差:' + msg.payload\n+ ' %,湿度差过大,请进行户外活动!';\nmessage += '\\n室内湿度:' + msg.payload + ' %';\nmessage += '\\n户外湿度:' + msg.payload + ' %\\n';\n\nmsg.payload = {\n \"msgtype\": \"text\", \n \"text\": {\n \"content\": message\n }, \n \"at\": {\n \"isAtAll\": true\n }\n}\n\nmsg.headers={\n 'Content-Type':'application/json',\n}\n\nmsg.url='https://oapi.dingtalk.com/robot/send?access_token=yourtoken';\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1000,
"y": 560,
"wires": [
[
"7c98e4ba6db6c234"
]
]
},
{
"id": "7c98e4ba6db6c234",
"type": "http request",
"z": "5bfc1ec08cb3472e",
"name": "POST 请求",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"senderr": false,
"x": 1190,
"y": 560,
"wires": [
[]
]
}
] Jarvis 发表于 2023-2-5 22:25
这样:
在 http request 节点中 url 中 只填 https://api.map.baidu.com/geoconv/v1/,内容 选择Append ...
搞定了,感谢!
页:
[1]