HTTP POST jsonprc request problems

Hi all
im fairly new to Node Red and up until now things have been going swimmingly.
I am trying to get an HTTP request (post) to work and non matter what i try i always get a 400 bad response.

The request is being used to control a device (not a pc) that runs an HTTPS server with a self signed cert.
I've built a request in postman that works like a charm but doing the same using an HTTP request node in NR just gets me a 400 response.

the json body of the request is

    "jsonrpc": "2.0",
    "method": "powerControl",
    "params": {
        "power": "powerOn",
        "AccessToken": "my secret access token"
    "id": 1

and it requires content-type and accept headers to be application/json. Simples it would seem.

Ive looked at the actual http requests using a postman mock server and the only difference is the content-length. Postman sets it to 201 and NR sets it to 143 for the exact same request.
Ive spent days trying different ways to achieve this using inject nodes to set the headers and payload, function nodes to do the same and it always returns the same.
I think im going slowly mad but any advice would be very much appreciated.
Oh and i have set my instance of NR to ignore SSL errors (because of the self signed cert on the server device)

Strange... by my calculation, that "body" you posted is 166 chars (with indentaions), so I'm guessing that you are trying to set the http request body to be just that JS object shown above.

If I recall, you need to JSON.stringify(...) your object (if using a function node), or pass the msg.payload through a json node. When you do that, you will likely get the extra escape chars and such, that postman is doing behind the scenes, to get you to content-length: 201

Qucik update. I came back to this after being away from it and noticed my node red install was waaaaay old. Updated to the current version and all is good. Not sure what the difference is but... it now works and im a happy bunny!.

Cheers Guys

1 Like

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