![](https://img.haomeiwen.com/i54923/0977f009350d06aa.png)
发送请求并将请求再发送出去
- GET请求
在控制台中输入
curl localhost:1880/test?name=wwmin
控制台会返回响应
PS C:\Windows\System32> curl localhost:1880/test?name=wwmin {"code":"200","msg":"接收成功,我成功响应啦","data":{"name":"wwmin"}}
- POST请求
curl localhost:1880/test --data "name=wwmin&age=12"
控制台响应
{"code":"200","msg":"接收成功,我成功响应啦","data":{"name":"wwmin","age":"12"}}
node-red导出的数据, 可将下方JSON导入到node-red
[
{
"id": "a3e934fe81fa2c30",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "e929f0904794d980",
"type": "http in",
"z": "a3e934fe81fa2c30",
"name": "",
"url": "/test",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 200,
"y": 340,
"wires": [
[
"0dd875eb138f2068",
"94e596ee49d158b8"
]
]
},
{
"id": "0dd875eb138f2068",
"type": "debug",
"z": "a3e934fe81fa2c30",
"name": "debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 510,
"y": 260,
"wires": []
},
{
"id": "94e596ee49d158b8",
"type": "function",
"z": "a3e934fe81fa2c30",
"name": "中间处理消息",
"func": "msg.payload = {\n \"code\": \"200\",\n \"msg\": \"接收成功,我成功响应啦\",\n \"data\": msg.payload\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 480,
"wires": [
[
"85b4604219556d81"
]
]
},
{
"id": "85b4604219556d81",
"type": "http response",
"z": "a3e934fe81fa2c30",
"name": "",
"statusCode": "200",
"headers": {},
"x": 820,
"y": 480,
"wires": []
},
{
"id": "753da0f879aec99c",
"type": "http in",
"z": "a3e934fe81fa2c30",
"name": "",
"url": "/test",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 200,
"y": 480,
"wires": [
[
"94e596ee49d158b8",
"0dd875eb138f2068"
]
]
},
{
"id": "b3cf4b2827989eb1",
"type": "comment",
"z": "a3e934fe81fa2c30",
"name": "发送请求并将请求再发送出去",
"info": "发送请求并将请求再发送出去\n\n1. GET请求\n在控制台中输入\n\n``\ncurl localhost:1880/test?name=wwmin\n``\n\n控制台会返回响应\n``\nPS C:\\Windows\\System32> curl localhost:1880/test?name=wwmin\n{\"code\":\"200\",\"msg\":\"接收成功,我成功响应啦\",\"data\":{\"name\":\"wwmin\"}}\n``\n\n2. POST请求\n\n``\n curl localhost:1880/test --data \"name=wwmin&age=12\"\n``\n\n控制台响应\n\n``\n{\"code\":\"200\",\"msg\":\"接收成功,我成功响应啦\",\"data\":{\"name\":\"wwmin\",\"age\":\"12\"}}\n``\n\n",
"x": 240,
"y": 260,
"wires": []
}
]
网友评论