"Error: connect ECONNREFUSED

I make post request to my api server, post using postman works very well but i can't make post request using node-red, please help need advice

msg.headers = {};
msg.headers={ 
      'Content-Type': 'application/json'
};

msg.method = "POST";
msg.url = "http://myserver:5000/datasensor";

msg.payload = {};
msg.payload = {
    "app_key":"41fd-bf8d-f558ee1cb84e",   
    "batt": raw.Bat,
    "level":raw.Level/100,
    "latitude":"0",
    "longitude":"0",
    "count":raw.fCnt,
    "temperature":"0"
 
  };

return msg;

and i got this error message
"Error: connect ECONNREFUSED http://myserver:5000/datasensor"

How is the http request node configured?

Hi @E1cid

like this

[{"id":"9f981220.1b5b1","type":"inject","z":"1a419334.cdb3ed","name":"","topic":"","payload":"{\"applicationID\":\"11\",\"applicationName\":\"dragino_lvl_1\",\"deviceName\":\"km5\",\"devEUI\":\"a84041cae1821b9b\",\"rxInfo\":[{\"gatewayID\":\"00800000a0003faa\",\"uplinkID\":\"6b9c8be5-522e-4cf1-bbfd-3bb1caa07a1b\",\"name\":\"gw_pkt\",\"time\":\"2020-06-25T02:31:28.478036Z\",\"rssi\":-116,\"loRaSNR\":-4.8,\"location\":{\"latitude\":0.14822,\"longitude\":117.45399,\"altitude\":145}}],\"txInfo\":{\"frequency\":923200000,\"dr\":2},\"adr\":true,\"fCnt\":220,\"fPort\":2,\"data\":\"DRACiQ==\",\"object\":{\"Bat\":3.5,\"Distance\":649,\"Level\":3051}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":1440,"wires":[["3e1fb14f.a0ecfe"]]},{"id":"3e1fb14f.a0ecfe","type":"function","z":"1a419334.cdb3ed","name":"Setup Request","func":"var msg;\nvar raw = msg.payload.object;\nmsg.headers = {};\nmsg.headers={ \n      'Content-Type': 'application/json',\n};\n\nmsg.method = \"POST\";\nmsg.url = \"http://myserver:5000/datasensor\";\n// msg.payload = raw;\nmsg.payload = {};\nmsg.payload = {\n    \"app_key\":\"3e20ffbf-c868-41fd-bf8d-f558ee1cb84e\",   \n    \"batt\": raw.Bat,\n    \"level\":raw.Level/100,\n    \"latitude\":\"0\",\n    \"longitude\":\"0\",\n    \"count\":raw.fCnt,\n    \"temperature\":\"0\"\n \n  };\n\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":1440,"wires":[["3fa39d3d.0939a2"]]},{"id":"3fa39d3d.0939a2","type":"http request","z":"1a419334.cdb3ed","name":"","method":"use","ret":"txt","url":"","tls":"","x":790,"y":1440,"wires":[["93581f26.350ee"]]},{"id":"93581f26.350ee","type":"debug","z":"1a419334.cdb3ed","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":1440,"wires":[]}]

It looks to me like your server does not accept/refusing post request with json body from node-red. How was the postman set up?
Try

msg.payload = JSON.stringify(msg.payload);

thats make me confused too, i'm using raw json to my post using postman

I'ts strange as the request works at this test site to https://ptsv2.com/t/7ybmy-1594053283/post

results can be seen here.
https://ptsv2.com/t/7ybmy-1594053283/d/6000863101321216

Maybe there is some strange white space on your api key. Try deleting it and typing it in instead of copy and paste.

Ok i'll try it thank you

Or maybe node-red only works with https not http, that is right?

Hi @E1cid i just realize that i run with old node-red, i try to run it using my new raspberry and it works, the question is if i upgrade the node-red it will delete all my setting? and also i run old version npm too can i upgrade it without erase my node-red setting?

I would think that all you would do is back up your flows and settings json. Then when you upgrade if they need to be replaced then you have a copy.

Thank you, the problem already solved

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.